我正在使用EclipseLink訪問SQLite數據庫。默認情況下,由於SQLite的向後兼容性,SQLite不強制執行外鍵約束。可以使用connection.createStatement().execute("PRAGMA foreign_keys=ON")
以每個連接爲基礎啓用外鍵約束。使用EclipseLink,將語句發送到每個新連接上的數據庫
當使用JDBC,下面的代碼做的伎倆:
Connection connection = DriverManager.getConnection("jdbc:sqlite:example.db");
Statement statement = connection.createStatement();
statement.execute("PRAGMA foreign_keys=ON");
// From now on, foreign key constraints are enforced on 'connection'
我將如何得到使用JPA/EclipseLink的同樣的效果?
我會在哪裏把那條線?我嘗試將它放入'SessionEventAdapter'的'postConnect()';但是我從哪裏得到'EntityManager'呢?當調用'Persistence.createEntityManagerFactory(「example」)。createEntityManager()'時,'postConnect()'事件被觸發。謝謝! – Feuermurmel 2011-06-03 20:42:37