Hi Michael,
Michael Horwitz wrote:
On 11/15/07, *Rob Hills* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
Michael Horwitz wrote:
> On the assumption that you have OpenSessionInView filter
uncommented,
> then yes. Transaction boundary is on the manager, so if you are
> calling multiple managers from a single action during the request,
> there may be an issue. A lot also depends on the Cascade parameters
> you have set on your entity relationships.
Yes, I have the "LazyLoadingFilter" and its mapping uncommented. Much
earlier I had some lazy loading issues that went away when I
uncommented
those filters.
With respect to Cascade, I'm using CascadeType.ALL on my parent
object,
which seemed like the right thing to do. The relevant annotations are
(in case I've done something else dopey there, which is quite
possible):
Parent POJO:
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY,
mappedBy="parent", targetEntity = Child.class)
public Set<Child> getChildren() {
return this.children;
}
Child POJO:
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="parent_id", nullable=false)
public Parent getParent() {
return parent;
}
Can't see anything wrong there. I know some people have claimed there
is some weirdness going on with CascadeType.ALL. You may want to try
adding the Hibernate specific @Cascade annotation with
CascadeType.MERGE ( the Hibernate CascadeType) and see if your problem
goes away. If it does please report back so we can alert others.....
I can confirm that CascadeType.MERGE makes no difference.
Any specific errors we can look at? May help to help, so to speak.
Well, the specific error I'm dealing with ATM occurs if I simply update
a single text field on the parent object using a form containing both
parent and child details. The error I get is a Hibernate one (which
doesn't show up in the Tomcat logs for some reason, but is displayed as
a comment on the page displaying the error. The full stack trace is 193
lines long so I'll just put the first few lines here now - you can have
the rest if you really want them :-)
org.springframework.dao.InvalidDataAccessApiUsageException: Write
operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL):
Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker
from transaction definition.
at
org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1095)
at
org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:764)
at
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
at
org.springframework.orm.hibernate3.HibernateTemplate.merge(HibernateTemplate.java:762)
at
org.appfuse.dao.hibernate.GenericDaoHibernate.save(GenericDaoHibernate.java:81)
at
au.com.myapp.dao.hibernate.ParentDaoHibernate.save(ParentDaoHibernate.java:131)
at
au.com.myapp.dao.hibernate.ParentDaoHibernate.save(ParentDaoHibernate.java:1)
at
org.appfuse.service.impl.GenericManagerImpl.save(GenericManagerImpl.java:89)
at
au.com.myapp.service.impl.ParentManagerImpl.save(ParentManagerImpl.java:103)
at
au.com.myapp.service.impl.ParentManagerImpl.save(ParentManagerImpl.java:1)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
at $Proxy35.save(Unknown Source)
at au.com.myapp.webapp.action.ParentAction.save(ParentAction.java:248)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
etc...
I've googled for the exception and turned up a few things, but none have
worked so far. I've seen some discussion about not-nullable columns in
a bi-directional relationship that I thought might be relevant. The
relationship in this case should probably be unidirectional - ie if the
child is removed from the parent list it should be deleted altogether,
but I've not yet worked out the right annotations to achieve that.
Thanks for looking at this,
Rob Hills
Waikiki, Western Australia
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]