我需要在没有persistence.xml的代码中创建EntityManager ... 我有
props.put("openjpa.ConnectionURL", "jdbc:sqlserver://databasehost:3306; DatabaseName=dbname; selectMethod=cursor;create=true");
props.put("openjpa.ConnectionDriverName","com.mysql.jdbc.Driver");
props.put("openjpa.ConnectionUserName", "dbname");
props.put("openjpa.ConnectionPassword", "password");
props.put("openjpa.jdbc.SynchronizeMappings", "buildSchema");
props.put("openjpa.Log", "DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE");
props.put("openjpa.RuntimeUnenhancedClasses", "supported");
EntityManagerFactory factory = Persistence.createEntityManagerFactory("wp");
em = factory.createEntityManager(props);
..当em = factory.createEntityManager(props)被调用时,我得到:
javax.persistence.PersistenceException: No persistence providers available for "wp" after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:182) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72) at dao.wp.WP_EMH.getCurrentEntityManager(WP_EMH.java:27)
据我所知,没有提及标记
表示的persistence.xml中的内容PROVIDER- org.apache.openjpa.persistence.PersistenceProviderImpl - / PROVIDER
我应该如何将其添加到属性?或者如何解决? 我的第二个问题是在persistence.xml中添加了实体类。如何用属性解决这个问题?
感谢
答案 0 :(得分:3)
方法
javax.persistence.Persistence.createEntityManagerFactory(
String persistenceUnitName);
需要persistence.xml
的配置。尝试提供您的房产地图
javax.persistence.Persistence.createEntityManagerFactory(
String persistenceUnitName, Map properties);
显然,财产集是不完整的;例如,它缺少持久化的类名:
properties.put("openjpa.MetaDataFactory", "jpa(Types=FQN.class1;FQN.class2;...)");