OpenJPA 在代码中创建 EntityManager,无需 persistence.xml,具有属性
我需要在没有 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)
我知道没有提到由标记
PROVIDER- org.apache.openjpa.persistence.PersistenceProviderImpl - / 表示的 persistence.xml 中的内容PROVIDER
我应该如何将其添加到属性中?或者如何解决? 我的第二个问题是在 persistence.xml 中添加了实体类。如何用属性来解决这个问题?
谢谢
I need to create EntityManager in code without persistence.xml ...
I have
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);
..and when em = factory.createEntityManager(props) is called I get :
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)
I understand that there is no mention about something that is in persistence.xml represented by tag
PROVIDER- org.apache.openjpa.persistence.PersistenceProviderImpl - /PROVIDER
How should I add this to Properties? Or how to solve it?
And my second question is that in persistence.xml are added classes of entities. How to solve this with properties?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该方法
需要来自
persistence.xml
的配置。尝试将您的属性映射提供给显然,属性集不完整;例如,它缺少持久的类名:
The method
expects configuration from
persistence.xml
. Try supplying your property map toClearly, though, the property set is incomplete; it lacks, for example, persistent class names: