I have two entity Beans. Both associated in a OneToMany relation.
Bean A is The parent bean.
Bean B is the child bean that holds a reference to A like this:
class BeanB ....
private BeanA a;
@ManyToOne(
fetch=FetchType.LAZY,
optional=false
)
@JoinColumn(
name="a",
nullable=false
)
public BeanA getA() {
return a;
}
public void setA(BeanA a) {
this.a = a;
}
Now on a client I retrieve on instance of BeanB. Whe I try to access elements
of A like
BeanB b = controller.find...
b.getA().getId()
the followin exception occurs:
org.hibernate.LazyInitializationException
could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no
Session
at
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
at
org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
at
org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)
...
I understand that BeanB is detached from the transaction context and behind the
scene a database transactionis needed to load BeanA. But how can I manage this
on a client?
I tried to put a transaction around the call
UserTransaction ut = (UserTransaction)(ctx.lookup("UserTransaction"));
ut.begin();
BeanB b = controller.find...
b.getA().getId()
ut.commit();
buth the result is the same? What can I do?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3942933#3942933
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3942933
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user