I use Hibernate 5.2.1 V with wildfly 10.0.1
When I call, criteria.getList() I get session/entitymanager closed exception.
Can somebody point me why I get this issue?
My code is like;
Code:
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void insertOrUpdate(T entity) {
try {
List<T> resultList = null;
if (entity.getCode() != null && entity.getId() ==null) {
resultList = crud().criteria(crud().eq("code", entity.getCode()).getCriteria()).list(); //---> Gives issue
Code:
List<T> result = getCriteria().list(); //Issue.
I create criteria instance as follows;
Code:
criteria = getSession().createCriteria(getEntityClass());
I create session like;
Code:
public Session getSession() {
if (session == null || !session.isOpen()) {
session = getEntityManager().unwrap(Session.class);
}
return session;
}
My peristence.xml
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="apidb-persistence-unit"
transaction-type="JTA">
<description>Forge Persistence Unit</description>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/lobDS</jta-data-source>
<shared-cache-mode>ALL</shared-cache-mode>
<class>xx.model.base.CRMEntity</class>
<class> ...</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="xx" />
<property name="javax.persistence.jdbc.password" value="xx" />
<!-- Scan for annotated classes and Hibernate mapping XML files -->
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.hbm2ddl.auto" value="" />
<property name="hibernate.enable_lazy_load_no_trans" value="true" />
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2" />
<property name="hibernate.connection.provider_class"
value="com.zaxxer.hikari.hibernate.HikariConnectionProvider" />
<property name="hibernate.hikari.minimumIdle" value="5" />
<property name="hibernate.hikari.maximumPoolSize" value="500" />
<property name="hibernate.hikari.idleTimeout" value="30000" />
<property name="hibernate.hikari.dataSourceClassName"
value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" />
<property name="hibernate.hikari.dataSource.url" value="jdbc:mysql://localhost:3306/rathadb" />
<property name="hibernate.hikari.dataSource.user" value="root" />
<property name="hibernate.hikari.dataSource.password" value="" />
<property name="hibernate.hikari.dataSource.cachePrepStmts"
value="true" />
<property name="hibernate.hikari.dataSource.prepStmtCacheSize"
value="1000" />
<property name="hibernate.hikari.dataSource.prepStmtCacheSqlLimit"
value="2048" />
<property name="hibernate.cache.use_second_level_cache"
value="true" />
<property name="hibernate.discriminator.ignore_explicit_for_joined"
value="true" />
</properties>
</persistence-unit>
</persistence>
ExceptionCode:
016-11-13 00:00:00,712 INFO [stdout] (default task-55) 2016-11-13 00:00:00 ERROR com.cdi.crud.infra.CrudService:insertOrUpdate(87): - Save or Update fails,
2016-11-13 00:00:00,712 INFO [stdout] (default task-55) java.lang.IllegalStateException: Session/EntityManager is closed
2016-11-13 00:00:00,712 INFO [stdout] (default task-55) at org.hibernate.internal.AbstractSharedSessionContract.checkOpen(AbstractSharedSessionContract.java:326) ~[hibernate-core-5.2.1.Final.jar!/:5.2.1.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.hibernate.engine.spi.SharedSessionContractImplementor.checkOpen(SharedSessionContractImplementor.java:126) ~[hibernate-core-5.2.1.Final.jar!/:5.2.1.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1826) ~[hibernate-core-5.2.1.Final.jar!/:5.2.1.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:365) ~[hibernate-core-5.2.1.Final.jar!/:5.2.1.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at com.cdi.crud.infra.Crud.list(Crud.java:451) ~[classes:?]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at com.cdi.crud.infra.CrudService.insertOrUpdate(CrudService.java:74) [classes:?]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at com.leightonobrien.lob2.service.autogen.TankObservationService.insertOrUpdate(TankObservationService.java:444) [classes:?]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at sun.reflect.GeneratedMethodAccessor247.invoke(Unknown Source) ~[?:?]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_111]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_111]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52) [wildfly-ee-10.1.0.Final.jar!/:10.1.0.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) [jboss-invocation-1.4.1.Final.jar!/:1.4.1.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437) [jboss-invocation-1.4.1.Final.jar!/:1.4.1.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82) [wildfly-weld-10.1.0.Final.jar!/:10.1.0.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93) [wildfly-weld-10.1.0.Final.jar!/:10.1.0.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63) [wildfly-ee-10.1.0.Final.jar!/:10.1.0.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) [jboss-invocation-1.4.1.Final.jar!/:1.4.1.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43) [wildfly-ejb3-10.1.0.Final.jar!/:10.1.0.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) [jboss-invocation-1.4.1.Final.jar!/:1.4.1.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [wildfly-jpa-10.1.0.Final.jar!/:10.1.0.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) [jboss-invocation-1.4.1.Final.jar!/:1.4.1.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437) [jboss-invocation-1.4.1.Final.jar!/:1.4.1.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64) [weld-core-impl-2.3.5.Final.jar!/:2.3.5.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83) [wildfly-weld-10.1.0.Final.jar!/:10.1.0.Final]
2016-11-13 00:00:00,713 INFO [stdout] (default task-55) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) [jboss-invocation-1.4.1.Final.jar!/:1.4.1.Final]
@