[英]Using hibernate 5.0.2 with glassfish4.0
I'm dealing with the configuration of my persistence.xml. 我正在处理persistence.xml的配置。 I think that I wrote the properties right, but there has to be a reason, why my tables are not created in MYSQL. 我认为我写的属性正确,但是必须有一个原因,为什么我的表没有在MYSQL中创建。
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="primary" transaction-type="JTA">
<jta-data-source>jdbc/__MyProject</jta-data-source>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<!-- needed when 'transaction-type="JTA"' -->
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />
</properties>
</persistence-unit>
</persistence>
I also tried update, validate and create. 我也尝试过更新,验证和创建。 When I use: 当我使用时:
<property name="eclipselink.ddl-generation" value="create-tables"/>
the tables are created, but I really want to know, if I just forgot to install something concerning glassfish or hibernate. 表已创建,但是我真的想知道,如果我只是忘记安装与玻璃鱼或冬眠有关的东西。
Here is a ahortcut from my pom.xml 这是我pom.xml的内容
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.0.2.Final</version>
</dependency>
<dependency> -->
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.2.Final</version>
</dependency>
I hope someone can help me. 我希望有一个人可以帮助我。
Glassfish by default is bundled with EclipseLink as the persistence provider. 默认情况下,Glassfish与EclipseLink捆绑在一起作为持久性提供程序。 As such if you must use a different provider, you will have to manually configure it. 因此,如果必须使用其他提供程序,则必须手动配置它。
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.1">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <!-- this -->
...
</persistence>
If you have no specific reason to be using Hibernate other than "that is what I have used in the past", consider just sticking with what is bundled with the container. 如果除了“这就是我过去使用的东西”之外,没有其他使用Hibernate的特殊原因,请考虑坚持使用与容器捆绑在一起的东西。 Glassfish is tested to work with EclipseLink, if you force Hibernate into the technology stack and you run into compatibility problems, you'll have a harder time getting help with it. 经过测试,Glassfish可以与EclipseLink一起使用,如果您将Hibernate强制加入技术堆栈,并且遇到兼容性问题,则将很难获得有关它的帮助。
If anything, it makes your application lighter as well since you don't need to deploy a pile of Hibernate classes with your application. 如果有的话,它也使您的应用程序更轻巧,因为您无需在应用程序中部署一堆Hibernate类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.