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