egars
Dec 6th, 2006, 02:24 PM
Hi all,
I've put an AbstractWizardFormController together that allows users to fill a persistent object. I use annotations (Hibernate 3.2.x) and solved a lot of problems with annotations and the
org.springframework.orm.hibernate3.support.OpenSes sionInViewInterceptor thing configured in a SimpleUrlHandlerMapping.
The wizard controller's JSPs consist of a success, a failure and a series of four form pages.
The second of these pages uses a property of the command bean that is actually annotated with @Transient, as I don't want this property to be persisted as such. Instead, that property dispatches a getter-method to a more generic way of storing some data:
getTelephoneNumber()
is annotated with @Transient
and returns one item, selected from a Set<CommunicationMethod>.
However, this does not work, unless I annotate the getter method for the collection as follows:
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
public Set<CommunicationMethod> getCommunicationMethods() {
.... etc....
Now, I see why it works as it does.
The EAGER annotation makes sure that all methods are fetched together with the object that is pointing at them.
My point is: why must I do this?
I would expect the interceptor to take care of this for me.
Instead, it throws a LazyIntializationException at me if I don't.
Why?
This is not so much of a problem that will keep me awake at night, but it does not seem to be very intuitive or logical.
Anyone?
Regards,
Egars
I've put an AbstractWizardFormController together that allows users to fill a persistent object. I use annotations (Hibernate 3.2.x) and solved a lot of problems with annotations and the
org.springframework.orm.hibernate3.support.OpenSes sionInViewInterceptor thing configured in a SimpleUrlHandlerMapping.
The wizard controller's JSPs consist of a success, a failure and a series of four form pages.
The second of these pages uses a property of the command bean that is actually annotated with @Transient, as I don't want this property to be persisted as such. Instead, that property dispatches a getter-method to a more generic way of storing some data:
getTelephoneNumber()
is annotated with @Transient
and returns one item, selected from a Set<CommunicationMethod>.
However, this does not work, unless I annotate the getter method for the collection as follows:
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
public Set<CommunicationMethod> getCommunicationMethods() {
.... etc....
Now, I see why it works as it does.
The EAGER annotation makes sure that all methods are fetched together with the object that is pointing at them.
My point is: why must I do this?
I would expect the interceptor to take care of this for me.
Instead, it throws a LazyIntializationException at me if I don't.
Why?
This is not so much of a problem that will keep me awake at night, but it does not seem to be very intuitive or logical.
Anyone?
Regards,
Egars