-1
Hi, I built a Maven j2ee-EAR project, but I’m having trouble setting up Hibernate/JPA. I added the dependencies in pom.xml, as below:
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${version.mysql.connector}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.12.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.12.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.1-api -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.7.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.common/hibernate-commons-annotations -->
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>5.0.1.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/antlr/antlr -->
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.2.12.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mchange/mchange-commons-java -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>mchange-commons-java</artifactId>
<version>0.2.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.ehcache/ehcache -->
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.2.12.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-jpamodelgen -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.2.12.Final</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
</dependencies>
And here’s persistence.xml:
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="vendero_pu" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>jdbc/vendero_ds</jta-data-source>
<class>br.com.vendero.model.Secao</class>
<properties>
<!-- Configuração do hibernate -->
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.archive.autodetection" value="class"/>
</properties>
</persistence-unit>
The JNDI name = jdbc/vendero_ds feature has been set up in Glassfish and is working, ping tested. But when executing the application the following exceptions are presented:
2017-12-23T00:51:37.792-0200|Information: HHH000204: Processing Persistenceunitinfo [ name: sales_pu ...] 2017-12-23T00:51:38.759-0200|Information: Booting Mojarra 2.2.14 ( 20161114-2152 2017-12-23T00:51:39.001-0200|Information: HHH000412: Hibernate Core {5.2.12.Final} 2017-12-23T00:51:39.020-0200|Information: HHH000206: Hibernate.properties not found 2017-12-23T00:51:39.992-0200|Information: HCANN000001: Hibernate Commons Annotations {5.0.1.Final} 2017-12-23T00:51:40.616-0200|Information: Loading application [__admingui] at [/] 2017-12-23T00:51:40.617-0200|Information: Loading application __admingui done in 6.385 ms 2017-12-23T00:51:41.482-0200|Information: HHH000400: Using dialect: org.hibernate.dialect.Mysql5innodbdialect 2017-12-23T00:51:43.971-0200|Grave: Exception while invoking class org.glassfish.persistence.jpa.Jpadeployer prepare method 2017-12-23T00:51:43.975-0200|Grave: javax.persistence.Persistenceexception: [Persistenceunit: vendero_pu] Unable to build Hibernate Sessionfactory at org.hibernate.jpa.boot.Internal.EntityManagerFactoryBuilderImpl.persistenceException(Entitymanagerfactorybuilderimpl.java:967) at org.hibernate.jpa.boot.Internal.EntityManagerFactoryBuilderImpl.build(Entitymanagerfactorybuilderimpl.java:892) at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(Hibernatepersistenceprovider.java:151) at org.glassfish.persistence.jpa.Persistenceunitloader.loadPU(Persistenceunitloader.java:199) at org.glassfish.persistence.jpa.Persistenceunitloader.(Persistenceunitloader.java:107) at org.glassfish.persistence.jpa.Jpadeployer$1.visitPUD(Jpadeployer.java:223) at org.glassfish.persistence.jpa.Jpadeployer$Persistenceunitdescriptoriterator.iteratePUDs(Jpadeployer.java:510) at org.glassfish.persistence.jpa.Jpadeployer.createEMFs(Jpadeployer.java:230) at org.glassfish.persistence.jpa.Jpadeployer.prepare(Jpadeployer.java:168) at com.sun.Enterprise.v3.server.Applicationlifecycle.prepareModule(Applicationlifecycle.java:925) at com.sun.Enterprise.v3.server.Applicationlifecycle.deploy(Applicationlifecycle.java:434) at com.sun.Enterprise.v3.server.Applicationlifecycle.deploy(Applicationlifecycle.java:219) at org.glassfish.Deployment.admin.Deploycommand.execute(Deploycommand.java:491) with.sun.Enterprise.v3.admin.Commandrunnerimpl$2$1.run(Commandrunnerimpl.java:539) with.sun.Enterprise.v3.admin.Commandrunnerimpl$2$1.run(Commandrunnerimpl.java:535) at java.security.Accesscontroller.doPrivileged(Native Method) at javax.security.auth.Subject.doas(Subject.java:360) com.sun.Enterprise.v3.admin.Commandrunnerimpl$2.execute(Commandrunnerimpl.java:534) with.sun.Enterprise.v3.admin.Commandrunnerimpl$3.run(Commandrunnerimpl.java:565) with.sun.Enterprise.v3.admin.Commandrunnerimpl$3.run(Commandrunnerimpl.java:557) at java.security.Accesscontroller.doPrivileged(Native Method) at javax.security.auth.Subject.doas(Subject.java:360) with.sun.Enterprise.v3.admin.Commandrunnerimpl.doCommand(Commandrunnerimpl.java:556) with.sun.Enterprise.v3.admin.Commandrunnerimpl.doCommand(Commandrunnerimpl.java:1464) with.sun.Enterprise.v3.admin.Commandrunnerimpl.access$1300(Commandrunnerimpl.java:109) with.sun.Enterprise.v3.admin.Commandrunnerimpl$Executioncontext.execute(Commandrunnerimpl.java:1846) with.sun.Enterprise.v3.admin.Commandrunnerimpl$Executioncontext.execute(Commandrunnerimpl.java:1722) at com.sun.Enterprise.v3.admin.Adminadapter.doCommand(Adminadapter.java:534) at com.sun.Enterprise.v3.admin.Adminadapter.onMissingResource(Adminadapter.java:224) at org.glassfish.Grizzly.http.server.StaticHttpHandlerBase.service(Statichttphandlerbase.java:189) at com.sun.Enterprise.v3.services.impl.Containermapper$Httphandlercallable.call(Containermapper.java:459) at com.sun.Enterprise.v3.services.impl.ContainerMapper.service(Containermapper.java:167) at org.glassfish.Grizzly.http.server.HttpHandler.runService(Httphandler.java:206) at org.glassfish.Grizzly.http.server.HttpHandler.doHandle(Httphandler.java:180) at org.glassfish.Grizzly.http.server.HttpServerFilter.handleRead(Httpserverfilter.java:235) at org.glassfish.Grizzly.filterchain.Executorresolver$9.execute(Executoresolver.java:119) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.executeFilter(Defaultfilterchain.java:283) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.executeChainPart(Defaultfilterchain.java:200) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.execute(Defaultfilterchain.java:132) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.process(Defaultfilterchain.java:111) at org.glassfish.Grizzly.ProcessorExecutor.execute(Processorexecutor.java:77) at org.glassfish.Grizzly.nio.transport.TCPNIOTransport.fireIOEvent(Tcpniotransport.java:536) at org.glassfish.Grizzly.strategies.Abstractiostrategy.fireIOEvent(Abstractiostrategy.java:112) at org.glassfish.Grizzly.strategies.Workerthreadiostrategy.run0(Workerthreadiostrategy.java:117) at org.glassfish.Grizzly.strategies.Workerthreadiostrategy.access$100(Workerthreadiostrategy.java:56) at org.glassfish.Grizzly.strategies.Workerthreadiostrategy$Workerthreadrunnable.run(Workerthreadiostrategy.java:137) at org.glassfish.Grizzly.threadpool.Abstractthreadpool$Worker.doWork(Abstractthreadpool.java:591) at org.glassfish.Grizzly.threadpool.Abstractthreadpool$Worker.run(Abstractthreadpool.java:571) at java.lang.Thread.run(Thread.java:748) Caused by: org.hibernate.engine.jndi.Jndiexception: Unable to find transaction
2017-12-23T00:51:44.004-0200|Grave: Exception while Preparing the app : [Persistenceunit: vendero_pu] Unable to build Hibernate Sessionfactory org.hibernate.engine.jndi.Jndiexception: Unable to find transaction manager at org.hibernate.engine.transaction.jta.platform.Internal.JBossAppServerJtaPlatform.locateTransactionManager(Jbossappserverjtaplatform.java:45) at org.hibernate.engine.transaction.jta.platform.Internal.AbstractJtaPlatform.retrieveTransactionManager(Abstractjtaplatform.java:87) at org.hibernate.Resource.transaction.backend.jta.Internal.DdlTransactionIsolatorJtaImpl.(Ddltransactionisolatorjtaimpl.java:42) at org.hibernate.Resource.transaction.backend.jta.Internal.JtaTransactionCoordinatorBuilderImpl.buildDdlTransactionIsolator(Jtatransacoorctiondinatorbuilderimpl.java:46) at org.hibernate.tool.schema.Internal.HibernateSchemaManagementTool.getDdlTransactionIsolator(Hibernateschemamanagementtool.java:178) at org.hibernate.tool.schema.Internal.AbstractSchemaMigrator.doMigration(Abstractschemamigrator.java:94) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(Schemamanagementtoolcoordinator.java:183) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(Schemamanagementtoolcoordinator.java:72) at org.hibernate.Internal.SessionFactoryImpl.(Sessionfactoryimpl.java:313) at org.hibernate.boot.internal.Sessionfactorybuilderimpl.build(Sessionfactorybuilderimpl.java:452) at org.hibernate.jpa.boot.Internal.EntityManagerFactoryBuilderImpl.build(Entitymanagerfactorybuilderimpl.java:889) at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(Hibernatepersistenceprovider.java:151) at org.glassfish.persistence.jpa.Persistenceunitloader.loadPU(Persistenceunitloader.java:199) at org.glassfish.persistence.jpa.Persistenceunitloader.(Persistenceunitloader.java:107) at org.glassfish.persistence.jpa.Jpadeployer$1.visitPUD(Jpadeployer.java:223) at org.glassfish.persistence.jpa.Jpadeployer$Persistenceunitdescriptoriterator.iteratePUDs(Jpadeployer.java:510) at org.glassfish.persistence.jpa.Jpadeployer.createEMFs(Jpadeployer.java:230) at org.glassfish.persistence.jpa.Jpadeployer.prepare(Jpadeployer.java:168) at com.sun.Enterprise.v3.server.Applicationlifecycle.prepareModule(Applicationlifecycle.java:925) at com.sun.Enterprise.v3.server.Applicationlifecycle.deploy(Applicationlifecycle.java:434) at com.sun.Enterprise.v3.server.Applicationlifecycle.deploy(Applicationlifecycle.java:219) at org.glassfish.Deployment.admin.Deploycommand.execute(Deploycommand.java:491) with.sun.Enterprise.v3.admin.Commandrunnerimpl$2$1.run(Commandrunnerimpl.java:539) with.sun.Enterprise.v3.admin.Commandrunnerimpl$2$1.run(Commandrunnerimpl.java:535) at java.security.Accesscontroller.doPrivileged(Native Method) at javax.security.auth.Subject.doas(Subject.java:360) com.sun.Enterprise.v3.admin.Commandrunnerimpl$2.execute(Commandrunnerimpl.java:534) with.sun.Enterprise.v3.admin.Commandrunnerimpl$3.run(Commandrunnerimpl.java:565) with.sun.Enterprise.v3.admin.Commandrunnerimpl$3.run(Commandrunnerimpl.java:557) at java.security.Accesscontroller.doPrivileged(Native Method) at javax.security.auth.Subject.doas(Subject.java:360) with.sun.Enterprise.v3.admin.Commandrunnerimpl.doCommand(Commandrunnerimpl.java:556) with.sun.Enterprise.v3.admin.Commandrunnerimpl.doCommand(Commandrunnerimpl.java:1464) with.sun.Enterprise.v3.admin.Commandrunnerimpl.access$1300(Commandrunnerimpl.java:109) with.sun.Enterprise.v3.admin.Commandrunnerimpl$Executioncontext.execute(Commandrunnerimpl.java:1846) with.sun.Enterprise.v3.admin.Commandrunnerimpl$Executioncontext.execute(Commandrunnerimpl.java:1722) at com.sun.Enterprise.v3.admin.Adminadapter.doCommand(Adminadapter.java:534) at com.sun.Enterprise.v3.admin.Adminadapter.onMissingResource(Adminadapter.java:224) at org.glassfish.Grizzly.http.server.StaticHttpHandlerBase.service(Statichttphandlerbase.java:189) at com.sun.Enterprise.v3.services.impl.Containermapper$Httphandlercallable.call(Containermapper.java:459) at com.sun.Enterprise.v3.services.impl.ContainerMapper.service(Containermapper.java:167) at org.glassfish.Grizzly.http.server.HttpHandler.runService(Httphandler.java:206) at org.glassfish.Grizzly.http.server.HttpHandler.doHandle(Httphandler.java:180) at org.glassfish.Grizzly.http.server.HttpServerFilter.handleRead(Httpserverfilter.java:235) at org.glassfish.Grizzly.filterchain.Executorresolver$9.execute(Executoresolver.java:119) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.executeFilter(Defaultfilterchain.java:283) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.executeChainPart(Defaultfilterchain.java:200) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.execute(Defaultfilterchain.java:132) at org.glassfish.Grizzly.filterchain.Defaultfilterchain.process(Defaultfilterchain.java:111) at org.glassfish.Grizzly.ProcessorExecutor.execute(Processorexecutor.java:77) at org.glassfish.Grizzly.nio.transport.TCPNIOTransport.fireIOEvent(Tcpniotransport.java:536) at org.glassfish.Grizzly.strategies.Abstractiostrategy.fireIOEvent(Abstractiostrategy.java:112) at org.glassfish.Grizzly.strategies.Workerthreadiostrategy.run0(Workerthreadiostrategy.java:117) at org.glassfish.Grizzly.strategies.Workerthreadiostrategy.access$100(Workerthreadiostrategy.java:56) at org.glassfish.Grizzly.strategies.Workerthreadiostrategy$Workerthreadrunnable.run(Workerthreadiostrategy.java:137) at org.glassfish.Grizzly.threadpool.Abstractthreadpool$Worker.doWork(Abstractthreadpool.java:591) at org.glassfish.Grizzly.threadpool.Abstractthreadpool$Worker.run(Abstractthreadpool.java:571) at java.lang.Thread.run(Thread.java:748) Caused by: org.hibernate.engine.jndi.Jndiexception: Unable to lookup JNDI name [java:jboss/Transactionmanager] at org.hibernate.engine.jndi.Internal.JndiServiceImpl.locate(Jndiserviceimpl.java:100) at org.hibernate.engine.transaction.jta.platform.Internal.JBossAppServerJtaPlatform.locateTransactionManager(Jbossappserverjtaplatform.java:38) ... 57 more Caused by: javax.naming.Namingexception: Lookup failed for 'java:jboss/Transactionmanager' in Serialcontext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Invocation Exception: Got null Componentinvocation ] with.sun.Enterprise.naming.impl.SerialContext.lookup(Serialcontext.java:491) with.sun.Enterprise.naming.impl.SerialContext.lookup(Serialcontext.java:438) with.sun.Enterprise.naming.impl.SerialContext.lookup(Serialcontext.java:622) at javax.naming.Initialcontext.lookup(Initialcontext.java:421) ...
Already I thank you for any help, because I can not find the reason that is causing these exceptions.
The problem was exactly this. Thank you so much for your help, Edjane!
– Paulo Lobo