简体   繁体   中英

Using hibernate 5.0.2 with glassfish4.0

I'm dealing with the configuration of my 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.

    <?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

    <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. 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. 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.

If anything, it makes your application lighter as well since you don't need to deploy a pile of Hibernate classes with your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM