-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: LazyInitializationException in seam/hibernate
PostPosted: Sun Oct 18, 2009 10:59 am 
Newbie

Joined: Wed Jun 18, 2008 8:28 pm
Posts: 3
Hello, again a LazyInit problem.. This time i don't undestand what im doing wrong. Well here is my code:

Persistence.xml parts

<persistence-unit name="${app.persistence.unit.name}" transaction-type="RESOURCE_LOCAL">
Code:
<provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>${app.jta.data.source}</non-jta-data-source>
    <property name="jboss.entity.manager.factory.jndi.name" value="${app.persistence.unit.jndi.name}"/>

Components.xml

Code:
<core:init debug="${env.debug}" distributable="${app.distributable}"
  jndi-pattern="${app.jndi.pattern}" /><!-- transaction-management-enabled="true" -->
  <persistence:entity-manager-factory name="${app.entity.manager.factory.name}" persistence-unit-name="${app.persistence.unit.name}"/>
    <persistence:managed-persistence-context name="em" auto-create="true" scope="EVENT"
                                             entity-manager-factory="#{${app.entity.manager.factory.name}}"/>
  <transaction:entity-transaction entity-manager="#{em}"/>


And the code:

In Department.java entiry i have

Code:
@JoinColumn(name = "COMPANY_ID", referencedColumnName = "ID")   
    @ManyToOne
   private Company companyId;


In company i have
Code:
@OneToMany(cascade = CascadeType.ALL, mappedBy = "companyId")
   @LazyCollection(LazyCollectionOption.TRUE)
   private Collection<Department> departmentCollection;


Now if i do this in CompanyAction which is Scoped as Conversation:

Code:
@In
   private EntityManager em;
public void test() {
      //em.getTransaction().begin();
      Company c = ((Company)Component.getInstance("company"));
      System.out.println("Nimi: " + c.getName());
      System.out.println("Open: " + em.isOpen());
      Collection<Department> depts = c.getDepartmentCollection();
      System.out.println("Lenks: " + depts.size());      
      //em.getTransaction().commit();
   }


I get LazyInitializationException.
If i remove the comments to start a transaction i get error that transaction is already active.
Now, LIE shows i have no session open. But how come if a transaction is already open?

I don't understand it, can anyone help me solve it. Or how is it best to use Seam managed persistence context or what even is the best?


Edit:

also tried with JPA and seam manager PC witht the following conf:

Code:
<core:init debug="${env.debug}" distributable="${app.distributable}"
  jndi-pattern="${app.jndi.pattern}" transaction-management-enabled="true" />
  <persistence:managed-persistence-context name="em"
                                     auto-create="true"
                                  persistence-unit-jndi-name="${app.persistence.unit.jndi.name}"/>
  <transaction:ejb-transaction />


Code:
  <persistence-unit name="${app.persistence.unit.name}" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>${app.jta.data.source}</jta-data-source>


Still get LIE


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.