0

i'm trying to configurate a JavaEE project with IntelliJ IDEA.

my configuration :

  • IDE Intellij (Jetbrains)
  • Glassfish (EJB Container)
  • JPA entities (Hibernate provider)
  • Database with WAMP (configured in persistence.xml)

Unfortunately, when i launch my project, a 404 page is displaying : EJBTransactionRolledbackException.

i don't understand this exception or this problem...maybe it's my file persistence.xml :

 <?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="PU" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
        <property name="hibernate.connection.user" value="root" />
        <property name="hibernate.connection.password" value="root" />
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/supbartering" />
        <property name="hibernate.hbm2ddl.auto" value="update" />
    </properties>
</persistence-unit>
</persistence>

and i use it with :

@PersistenceContext(unitName = "PU")
private EntityManager mEntityManager;

It's the first time i 'm using Intellij with JEE project and GlassFish server, but i can't achieve the good configuration.

Boris S.
  • 1,068
  • 1
  • 8
  • 18
  • 1
    can you post your full exception? – soorapadman Jan 19 '16 at 12:46
  • 1
    Have you tested with `transaction-type="JTA"` instead of "JPA"? Check: http://stackoverflow.com/questions/27713599/javax-ejb-ejbexception-java-lang-illegalstateexception-unable-to-retrieve-entit?lq=1 – Baderous Jan 19 '16 at 12:47
  • @Baderous, it's already JTA :s ...Mistake =). – Boris S. Jan 19 '16 at 12:58
  • 1
    why use Hibernate specific connection properties when there are JPA standard ones? makes no sense. If using JTA then need a jtaDataSource not connectionURL/user/password – Neil Stockton Jan 19 '16 at 14:04
  • @NeilStockton Thank you. Can you post an explain response with JTA and jtaDataSource ?? i don't know where i must put URL,user, password...and jtaDataSource – Boris S. Jan 19 '16 at 14:43

1 Answers1

1

You are using Hibernate specific "local datasource" properties, yet you claim to want to use JTA transactions. That is inconsistent. See section 8.2.1.2 of the JPA spec

The transaction-type attribute is used to specify whether the entity managers provided by the entity manager factory for the persistence unit must be JTA entity managers or resource-local entity managers. The value of this element is JTA or RESOURCE_LOCAL. A transaction-type of JTA assumes that a JTA data source will be provided—either as specified by the jta-data-source element or provided by the container. In general, in Java EE environments, a transaction-type of RESOURCE_LOCAL assumes that a non-JTA datasource will be provided. In a Java EE environment, if this element is not specified, the default is JTA. In a Java SE environment, if this element is not specified, the default is RESOURCE_LOCAL.

So you either use JTA, define your JTA data source externally, and specify the "jtaDataSource" in persistence.xml (and remove the url/user/password/driver), OR you use RESOURCE_LOCAL transactions and define the data source via connection URL/user/password/driver properties (and use the standard javax.persistence properties like this link shows).

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29