JPA 与 H2 数据库的连接
我正在开发一个带有 JPA 的 hibernate 项目,并尝试使用 H2(嵌入式数据库)获取工作 persistence.xml。
Persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="DefaultPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>entity.user</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:h2:/~test" /> -->
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"></property>
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.password" value="admin" />
<property name="hibernate.connection.username" value="admin" />
</properties>
</persistence-unit>
</persistence>
但是我的这不起作用,我总是收到错误
“无法创建EntityManagerFactory”
EntityManagerFactory emf = Persistence.createEntityManagerFactory("DefaultPersistenceUnit");
。谁能给我提供有效的 persistence.xml 吗?
I am developing a hibernate with JPA project and trying to get the working persistence.xml by using H2(Embedded database).
Persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="DefaultPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>entity.user</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:h2:/~test" /> -->
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"></property>
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.password" value="admin" />
<property name="hibernate.connection.username" value="admin" />
</properties>
</persistence-unit>
</persistence>
But my this is not working, always I am getting the error
"Unable to create EntityManagerFactory"
EntityManagerFactory emf = Persistence.createEntityManagerFactory("DefaultPersistenceUnit");
. Can anyonw provide me the working persistence.xml?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你用的是Spring吗?如果是这样,只要容器不提供 EntityManagerFactory,您就可以尝试此操作
Are you using Spring? If so you could try this as long as the EntityManagerFactory is not provided by a container