-->
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.  [ 9 posts ] 
Author Message
 Post subject: Hibernate Xdoclet question
PostPosted: Mon Nov 08, 2004 2:01 am 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
Hibernate version:2.1.1

Name and version of the database you are using:MySQL 4

I have two class:

Rights
--------
Long: id
ConditionType:conditionType
List:conditionTypeValues

ConditionTypeValue
------------------------
Long: id
String: value
Boolean: hasText

I have implemented a unidirectional many-to-many relationship between the two classes; I'm using hibernate with Xdoclet so the code I've written in Rights.java is as follows:

Code:
/**
    * @return Returns the conditionTypeValue.
    * @hibernate.bag
    *       table="table_join_rights_condition_type_value"
    *       cascade="save-update"
    * @hibernate.collection-key
    *       column="fk_rights_id"
    * @hibernate.collection-many-to-many
    *       class="au.edu.tlf.lips.model.ConditionTypeValue"
    *       column="fk_condition_type_value_id"
    */
   public List getConditionTypeValue() {
      return conditionTypeValue;
   }
   
   /**
    * @param conditionTypeValue The conditionTypeValue to set.
    */
   public void setConditionTypeValue(List conditionTypeValue) {
      this.conditionTypeValue = conditionTypeValue;
   }


This creates the following table structure in MySQL:

Code:
create table condition_type_value (
id BIGINT NOT NULL AUTO_INCREMENT,
has_text BIT,
value VARCHAR(255),
primary key (id)
);

create table table_join_rights_condition_type_value (
fk_rights_id BIGINT not null,
fk_condition_type_value_id BIGINT not null
);

create table rights (
id BIGINT NOT NULL AUTO_INCREMENT,
fk_condition_type_id BIGINT,
primary key (id)
);


The question I would like to ask is, I have a requirement save a String field against each entry in table_join_rights_condition_type_value

1)How do you set this up correctly, to create another attribute in table_join_rights_condition_type_value of type string?
2)Is it possible using Xdoclet?
3)How will I save data to that attribute if can be created?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 5:12 am 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
What is puprose of this field?

Normally you will not see this link table at all because it is not entity.
If this string value is unique, you could swotch to map mapping instead - in this case it will be @hibernate.collection-index ( if you user xdoclet 1.2.x )

or @hibernate.index for 2.0 :

http://docs.codehaus.org/display/XDOCLE ... nate.index

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 6:43 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
You might want to look at explicitly mapping the many-many link table with an explicit class. Then any extra atributes are easy to map.

Something like:
Code:
class RightsConditionTypeValueRelationship {
  private Rights rights;
  private ConditionTypeValue value;
  private String newStringField'
  ...
  appropriate mappings
  ...
}


Yes, it's an extra class.
But:
(a) the HB team themselves recommend this approach
(b) it will be easier to extend with yet more attributes or even extra associations (which is really difficult otherwise)
(c) it will make it easier for non/new-Hibernate users to understand
(d) it's more straightforward to query, especially using the Criteria API

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 09, 2004 5:32 am 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
Thanks for the tip on that, very grateful.

Quick Xdoclet question that arises from there. I've set up the RightsConditionTypeValueRelationship as you suggested and in Rights and ConditionTypeValue but with my current settings for the method I'm getting the following error:

Code:
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection


This is the Xdoclet code that I have in the Rights class. What am I doing incorrectly?

Code:
/**
    * @return Returns the rightsConditionTypeValues.
    * @hibernate.bag
    *       name="rightsConditionTypeValues"
    *       cascade="save-update"
    *       lazy="true"
    * @hibernate.collection-key
    *       column="fk_rights_id"
    * @hibernate.collection-many-to-many
    *       column="fk_condition_type_value_id"
    *       class="au.edu.tlf.lips.model.RightsConditionTypeValueRelationship"
    */
   public List getRightsConditionTypeValues() {
      return rightsConditionTypeValues;
   }
   
   /**
    * @param rightsConditionTypeValues The rightsConditionTypeValues to set.
    */
   public void setRightsConditionTypeValues(List rightsConditionTypeValues) {
      this.rightsConditionTypeValues = rightsConditionTypeValues;
   }


SQL Code:
Code:
create table condition_type_value (
id BIGINT NOT NULL AUTO_INCREMENT,
has_text BIT,
is_defaulted_value BIT,
value VARCHAR(255),
fk_condition_type_value_id BIGINT,
primary key (id)
);

create table rights_condition_type_value_relationship (
id BIGINT NOT NULL AUTO_INCREMENT,
fk_condition_type_value_id BIGINT,
notes VARCHAR(255),
fk_rights_id BIGINT,
primary key (id)
);

create table rights (
id BIGINT NOT NULL AUTO_INCREMENT,
rights_id BIGINT,
fk_rights_type_id BIGINT,
fk_condition_type_id BIGINT,
primary key (id)
);



Stack trace:
Code:
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:201)
   at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
   at net.sf.hibernate.collection.Bag.iterator(Bag.java:256)
   at org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(ForEachSupport.java:360)
   at org.apache.taglibs.standard.tag.common.core.ForEachSupport.supportedTypeForEachIterator(ForEachSupport.java:238)
   at org.apache.taglibs.standard.tag.common.core.ForEachSupport.prepare(ForEachSupport.java:172)
   at javax.servlet.jsp.jstl.core.LoopTagSupport.doStartTag(LoopTagSupport.java:262)
   at org.apache.taglibs.standard.tag.el.core.ForEachTag.doStartTag(ForEachTag.java:105)
   at org.apache.jsp.WEB_002dINF.pages.licenceDetail_jsp._jspx_meth_c_forEach_8(licenceDetail_jsp.java:2167)
   at org.apache.jsp.WEB_002dINF.pages.licenceDetail_jsp._jspx_meth_c_forEach_7(licenceDetail_jsp.java:2134)
   at org.apache.jsp.WEB_002dINF.pages.licenceDetail_jsp._jspx_meth_c_if_6(licenceDetail_jsp.java:2086)
   at org.apache.jsp.WEB_002dINF.pages.licenceDetail_jsp._jspx_meth_c_forEach_6(licenceDetail_jsp.java:2043)
   at org.apache.jsp.WEB_002dINF.pages.licenceDetail_jsp._jspx_meth_c_if_5(licenceDetail_jsp.java:1944)
   at org.apache.jsp.WEB_002dINF.pages.licenceDetail_jsp._jspx_meth_c_forEach_5(licenceDetail_jsp.java:1882)
   at org.apache.jsp.WEB_002dINF.pages.licenceDetail_jsp._jspService(licenceDetail_jsp.java:296)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:750)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:636)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:546)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:1002)
   at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:626)
   at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:142)
   at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:178)
   at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:801)
   at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:933)
   at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:503)
   at org.apache.jsp.layouts.baseLayout_jsp._jspx_meth_tiles_insert_5(baseLayout_jsp.java:1201)
   at org.apache.jsp.layouts.baseLayout_jsp._jspService(baseLayout_jsp.java:319)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:750)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:510)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:445)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:359)
   at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:88)
   at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:238)
   at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:644)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:535)
   at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:321)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:73)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:73)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at com.opensymphony.clickstream.ClickstreamFilter.doFilter(ClickstreamFilter.java:42)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at au.edu.tlf.lips.webapp.filter.ActionFilter.doFilter(ActionFilter.java:160)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at au.edu.tlf.lips.webapp.filter.BreadcrumbFilter.doFilter(BreadcrumbFilter.java:162)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.springframework.orm.hibernate.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:170)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:73)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:88)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at au.edu.tlf.lips.webapp.filter.GZIPFilter.doFilter(GZIPFilter.java:51)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:587)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:184)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:833)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:732)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:619)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:688)
   at java.lang.Thread.run(Unknown Source)
Caused by: net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: 2, of class: au.edu.tlf.lips.model.RightsConditionTypeValueRelationship
   at net.sf.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java:38)
   at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1943)
   at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:68)
   at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:232)
   at net.sf.hibernate.type.EntityType.nullSafeGet(EntityType.java:154)
   at net.sf.hibernate.collection.AbstractCollectionPersister.readElement(AbstractCollectionPersister.java:363)
   at net.sf.hibernate.collection.Bag.readFrom(Bag.java:75)
   at net.sf.hibernate.loader.Loader.readCollectionElement(Loader.java:305)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:219)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:915)
   at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:890)
   at net.sf.hibernate.loader.CollectionLoader.initialize(CollectionLoader.java:83)
   at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
   at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3259)
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:195)
   ... 101 more



Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 09, 2004 8:43 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
You need to convert the collections that were defined as "many-to-many" to "one-to-many", since the new class is explicitly handling the man-to-many nature of the association.

Hibernate In Action has a good explanation of it, and there have been other topics on the forums about it too (search for thing like "ternary" and "many-to-many"). Not sure if there are any topics about it on the wiki though.

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 09, 2004 11:11 pm 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
Hi Shron,

Thanks for the tips, I noticed the many-to-many that was a topo on my part but again thanks. I've order a copy of Hibernate in Action and am currently waiting its arrival.

Hence I'm hoping you might be able to help me with another quick question I have. When saving and update related collections what is best practice within Hibernate.

For instance:

When I call to save/update rights.setRightsConditionTypeValues(list) those new values are entered into my DB correctly but the old values are also still in the DB too.

Is it best practice to first delete all the related values that will be updated then set the new values OR call rights.getRightsConditionTypeValues() iterate through the results and update appropriate values within the returned list then call rights.setRightsConditionTypeValues(updatedlist) I'll be doing this in the web tier of the system that does not feel sound. Are either of my suggested solutions correct?

Thanks again for all you tips,
Barry


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 10, 2004 12:11 am 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Either is a valid method in Hibernate.

It's decided byt the cascade attribute. Your current setting of "save-update" requires that you explicitly call Session.delete() on the children that you want deleted. If you set your cascade option to "delete-orphan" (or whatever it is - look in the doco), then hibernate will delete the rows that aren't pointed at any longer by the parent.

Which is more valid? Well, that's up to you. But if my memory serves (which it frequently doesn't) - Gavin didn't want to put the delete-orphan option in and had to be hassled a fair bit to do it.

So you could say that, a while ago at least, the Hibernate team considered the explicit deletion pattern to be more valid.

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 10, 2004 12:51 am 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
That was the conclusion that I came up with but unfortunately when I try to do this I'm getting the following error.

Code:
org.springframework.orm.hibernate.HibernateObjectRetrievalFailureException: deleted object would be re-saved by cascade (remove deleted object from associations): 1, of class: au.edu.tlf.lips.model.Rights; nested exception is net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): 1, of class: au.edu.tlf.lips.model.Rights
net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): 1, of class: au.edu.tlf.lips.model.Rights
   at net.sf.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:745)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:723)
   at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1368)
   at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
   at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
   at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482)
   at net.sf.hibernate.impl.SessionImpl.preFlushEntities(SessionImpl.java:2664)
   at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2239)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2228)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:447)
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:375)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:241)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:66)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:152)
   at $Proxy31.removeRights(Unknown Source)
   at au.edu.tlf.lips.webapp.action.RightsFormController.onSubmit(RightsFormController.java:226)
   at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:223)
   at au.edu.tlf.lips.webapp.action.RightsFormController.processFormSubmission(RightsFormController.java:155)
   at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:237)
   at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:121)
   at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:495)
   at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:321)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:73)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:73)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at com.opensymphony.clickstream.ClickstreamFilter.doFilter(ClickstreamFilter.java:42)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at au.edu.tlf.lips.webapp.filter.ActionFilter.doFilter(ActionFilter.java:160)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at au.edu.tlf.lips.webapp.filter.BreadcrumbFilter.doFilter(BreadcrumbFilter.java:162)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.springframework.orm.hibernate.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:170)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:73)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:88)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at au.edu.tlf.lips.webapp.filter.GZIPFilter.doFilter(GZIPFilter.java:51)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:257)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:587)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:184)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:567)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:206)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:833)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:732)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:619)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:688)
   at java.lang.Thread.run(Unknown Source)


The code in my MVC layer is as follows, quick back ground; Rights are associated to a Licence in a one-to-many relationship
Code:
   public ModelAndView onSubmit(HttpServletRequest request,
         HttpServletResponse response, Object command, BindException errors)
         throws Exception {
      if (log.isDebugEnabled()) {
         log.debug("entering 'onSubmit' method...");
      }

      //define the licence
      Licence licence = (Licence) command;
      
      //set up list to contain all rights
      List rights = new LinkedList();
      
      //a single instance of a right
      Rights right = null;
      
      //success screen
      String success = getSuccessView();
      
      //get the rights type
      String rightsTypeId = request.getParameter("rightsTypeId");
      RightsType rightsType = rightsTypeMgr.getRightsType(Long.valueOf(rightsTypeId));
      
      //get conditions that applied to that rightsType
      List conditionTypes = conditionTypeMgr.getAllCondtionTypesForRightsType(rightsType);      
      Iterator keys = conditionTypes.iterator();
      
      //for each condition set actual right information
      while(keys.hasNext()){
         ConditionType conditionType = (ConditionType)keys.next();
               
         //populate right object
         right = new Rights();
         right.setLicence(licence);
         right.setRightsType(rightsType);
         right.setConditionType(conditionType);               
         
         rightsMgr.saveRights(right);
         
         List conditionTypeValuesToAddToRights       = new LinkedList();                           
                  
         String[] requestIds = request.getParameterValues(conditionType.getId().toString());
         
         for(int i=0; i<requestIds.length; i++) {
            
            ConditionTypeValue conditionTypeValue = conditionTypeValueMgr.getConditionTypeValue(Long.valueOf(requestIds[i]));
            
            RightsConditionTypeValueRelationship rightsConditionTypeValueRelationship = new RightsConditionTypeValueRelationship();
            
            rightsConditionTypeValueRelationship.setRights(right);
            rightsConditionTypeValueRelationship.setConditionTypeValue(conditionTypeValue);
            
            if(conditionTypeValue.getHasText() == Boolean.TRUE) {
               String notes = request.getParameter(conditionTypeValue.getId() + Constants.TEXT_FIELD);
               rightsConditionTypeValueRelationship.setNotes(notes);
            }

            rightsConditionTypeValueRelationshipMgr.saveRightsConditionTypeValueRelationship(rightsConditionTypeValueRelationship);
            
         }
         rights.add(right);
      }            
      
      licence.setRights(rights);
      
      rightsMgr.removeRights(licence);
      
      licenceMgr.saveLicence(licence);

      String message = getMessageSourceAccessor().getMessage(
            "rights.updated",
            new Object[] { licence.getLicenceDescriptor() });

      saveMessage(request, message);

      success = "viewLicence.html?id=" + licence.getId();

      return new ModelAndView(new RedirectView(success));
   }


rightsMgr.removeRights(licence); seems to cause all the problems.

If I remove this line, all details will be saved correctly but old values still remain in the DB (i.e.) possible duplicates etc. This is where my understanding is not very good with regard to Hibernate. Shouldn't those values removed by the cascade.... What am I doing incorrect? Any ideas?

Barry


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 10, 2004 1:16 am 
Beginner
Beginner

Joined: Thu Sep 23, 2004 6:03 am
Posts: 27
Just a note on that. The cascade is set to all in my current xdoclet heading

Code:
/**
    * @return Returns the rightsConditionTypeValues.
    * @hibernate.bag
    *       name="rightsConditionTypeValues"
    *       cascade="all"
    *       lazy="true"
    * @hibernate.collection-key
    *       column="fk_rights_id"
    * @hibernate.collection-one-to-many
    *       class="au.edu.tlf.lips.model.RightsConditionTypeValueRelationship"
    */
   public List getRightsConditionTypeValues() {
      return rightsConditionTypeValues;
   }
   
   /**
    * @param rightsConditionTypeValues The rightsConditionTypeValues to set.
    */
   public void setRightsConditionTypeValues(List rightsConditionTypeValues) {
      this.rightsConditionTypeValues = rightsConditionTypeValues;
   }


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

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.