Hi, We are working on migrating our project from Seam 2, Hibernate 3, and JSf 1.2 running on JBoss 5 to Seam 3 (or deltaspike once its ready), Hibernate 4, and JSF 2 running on jboss 7. We have run into an issue we cannot solve related to LIE (LazyInitializationException) with hibernate session.
Stack trace is below. We have our persistence.xml under our core/ejb project ~/src/main/resources/meta-inf, also shown below. We have tried with CDI/Seam 3 pojo and EJBs. We have also tried with @Inject or @PersistentContext **with extended option) with no luck. What we do not have is some CDI producer for EntityManager or EntityManagerFactory. It seems if we try to add something like that like the seam 3 documentation suggests we get common WELD duplicate producer exceptions on app server startup http://docs.jboss.org/seam/3/latest/reference/en-US/html_single/#d0e4926
What we do know... We have a transaction and do a log with entityMangaer.find and render this entity on page. We do a call to update it and before calling saveOrUpdate we get the LIE working with the entity to recompute something that uses a lazy fetched one to one entity. So customer has a one to one with credit worksheet..
@NotAudited @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @org.hibernate.annotations.LazyToOne(LazyToOneOption.PROXY) @Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.MERGE }) @JoinColumn(name = "worksheet_fk") @Fetch(FetchMode.SELECT) public CustomerWorksheet getWorksheet() {
@Named("customerFile") @ConversationScoped @Transactional public class CustomerFileBean
load works.. @Transactional public void load() { cust = entityManager.find(Customer.class, new Long(1));
update blows up (note entitytManager.contains will return false) boolean contains = entityManager.contains(cust); if(contains == false) entityManager.merge(cust); contains = entityManager.contains(cust); cust.compute(true);
with or without the merge it doesn't matter. Compute blows up.
Comparing the entity manager to string and hashcode they match between requests, however if I get the hibernate session the toString and hashcode do NOT match. I would expect same hibernate session for seam extended persistence context.
Any ideas??
<?xml version="1.0" encoding="UTF-8"?> <!-- Persistence deployment descriptor for dev profile --> <persistence version="2.0" 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">
<persistence-unit name="oflows"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:jboss/datasources/oFlowsDS</jta-data-source>
<properties> <property name="hibernate.hbm2ddl.auto" value="validate" /> <property name="hibernate.show_sql" value="false" /> <property name="hibernate.format_sql" value="true" /> <property name="hibernate.cache.use_second_level_cache" value="true" /> <property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
<property name="jboss.entity.manager.factory.jndi.name" value="java:/oflowsEntityManagerFactory" /> <property name="hibernate.ejb.naming_strategy" value="com.oflows.util.hibernate.OflowsNamingStrategy" /> <property name="hibernate.dialect" value="com.oflows.seam.entity.util.CustomMysql5Dialect" /> <property name="hibernate.jdbc.batch_size" value="20" /> <property name="hibernate.connection.max_allowed_packet" value="33,554,432" />
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:149) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185) [hibernate-core-4.0.1.Final.jar:4.0.1.Final] at com.oflows.seam.entity.CustomerWorksheet_$$_javassist_174.getCredit(CustomerWorksheet_$$_javassist_174.java) [:] at com.oflows.seam.entity.Customer.compute(Customer.java:441) [:] at com.oflows.seam.session.oconsole.CustomerFileBean.updateInformation(CustomerFileBean.java:115) [:] at com.oflows.seam.session.oconsole.CustomerFileBean$Proxy$_$$_WeldSubclass.updateInformation(CustomerFileBean$Proxy$_$$_WeldSubclass.java) [:] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0] at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0] at org.jboss.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:114) [jboss-interceptor-core-2.0.0.Final.jar:2.0.0.Final] at org.jboss.interceptor.proxy.InterceptorInvocationContext.proceed(InterceptorInvocationContext.java:143) [jboss-interceptor-core-2.0.0.Final.jar:2.0.0.Final] at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:152) [seam-transaction-3.1.0.Final.jar:3.1.0.Final]
|