您可以在運行時創建自己的EntityManager:
Map map = new HashMap();
map.put("javax.persistence.jdbc.password", "password");
map.put("javax.persistence.jdbc.user", "root");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("MyPU",map);
EntityManager em = emf.createEntityManager(map);
一些EclipseLink的屬性名稱:
<property name="eclipselink.target-database" value="DERBY"/>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="eclipselink.jdbc.url" value="jdbc:derby://localhost:1527/02DB;create=true"/>
<property name="eclipselink.jdbc.user" value="user"/>
<property name="eclipselink.jdbc.password" value="password"/>
呀,但正如我所說,我跑我應用程序在容器中,所以我注入EntityManager而不是自己創建它。對於Java SE,您的方法就足夠了,我同意。不過謝謝你的建議。 – jFrenetic 2013-02-17 16:10:25