vendredi 3 avril 2015

Spring Data JPA - Hibernate - Closes transaction after getting id from sequence

I have an application that uses Spring Data JPA and Oracle database for the backend. The Entity class has an id column that is generated by the sequence in the database.


The entity class is:



@Entity
@Table(name="ROLES")
public class AppRole {

@Id
@SequenceGenerator(name="SEQ_ROLES", sequenceName="SEQ_ROLES", allocationSize = 1)
@GeneratedValue(generator="SEQ_ROLES", strategy = GenerationType.SEQUENCE)
private Long id;

private String name;

private String description;

.. getters and setters
}


and spring data jpa repository interface is:



public interface AppRoleRepository extends JpaRepository<AppRole, Long>, JpaSpecificationExecutor<AppRole> {}


But, whenever I tried to persist an entity of AppRole, it throws an exception background but continues to work fine. The page renders well, nothing happens to client side. But in server console, it outputs these lines;



11:39:35.973 DEBUG JpaTransactionManager - Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@640f233e]
11:39:35.977 DEBUG SQL - select SEQ_ROLES.nextval from dual
11:39:36.036 DEBUG SequenceGenerator - Sequence identifier generated: BasicHolder[java.lang.Long[36]]
11:39:36.036 DEBUG AbstractSaveEventListener - Generated identifier: 36, using strategy: org.hibernate.id.SequenceHiLoGenerator
11:39:36.036 DEBUG AbstractFlushingEventListener - Processing flush-time cascades
11:39:36.036 DEBUG AbstractFlushingEventListener - Dirty checking collections
11:39:36.037 DEBUG AbstractFlushingEventListener - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
11:39:36.037 DEBUG AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
11:39:36.037 DEBUG EntityPrinter - Listing entities:
11:39:36.037 DEBUG EntityPrinter - AppRole{name=asdasd, description=asdasd, id=36}
11:39:36.051 DEBUG SQL - insert into ROLES (description, name, id) values (?, ?, ?)
11:39:36.091 DEBUG SqlExceptionHelper - could not log warnings
java.sql.SQLRecoverableException: Closed Statement
at oracle.jdbc.driver.OracleClosedStatement.getWarnings(OracleClosedStatement.java:6501) ~[ojdbc6-11.2.0.4.jar:11.2.0.3.0]
at oracle.jdbc.driver.OracleStatementWrapper.getWarnings(OracleStatementWrapper.java:1571) ~[ojdbc6-11.2.0.4.jar:11.2.0.3.0]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.handleAndClearWarnings(SqlExceptionHelper.java:291) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]


I am having this exception. It seems that, the transaction and the connection closes after getting id from the sequence. Then it recovers and opens a new connection and executes this insert statement in this new connection.


Is this normal to have or am I mis-used or mis-configured something wrong?


Thanks a lot.


Aucun commentaire:

Enregistrer un commentaire