Hello,

I'm newbie to LCDS, and learn how to use it. I have tried some basic
tutorials and success to build it. Now I have an idea to manage my data
but don't know how to do in a good way.

So. In my database, I have a "gabarit" table, who is linked in
one-to-many association to a "gabaritItem" table.
First I would like to retrieve all the gabarits from the DB, with for
each gabarit its gabaritItem's.

My GabaritVO java class :

package com.myapp.app.vo;

import java.util.Set;

public class GabaritVO
{

     private int id;
     private String name;
     private String desc;
     private Set gabaritItems;

     public int getId()
     {        return id;    }
     public void setId(int id)
     {        this.id = id;    }

     public String getName()
     {        return name;    }
     public void setName(String name)
     {        this.name = name;    }

     public String getDesc()
     {        return desc;    }
     public void setDesc(String desc)
     {        this.desc = desc;    }

     public Set getGabaritItems()
     {        return gabaritItems;    }
     public void setGabaritItems(Set gabaritItems)
     {        this.gabaritItems = gabaritItems;    }
}



I have a GabaritItemVO java class for the gabaritItem's subdata.


Second, I map my classes with this GabaritVO.hbm.xml file :

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
         "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd";
<http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd> >
<hibernate-mapping>
     <class name="com.myapp.app.vo.GabaritVO" table="gabarit">
         <id name="id" column="gabaritid">
             <generator class="native"/>
         </id>
         <property name="name" column="gabaritname" />
         <property name="desc" column="gabaritdesc" />

         <set name="gabaritItems">
             <key column="gabaritid" />
             <one-to-many class="com.myapp.app.vo.GabaritItemVO" />
         </set>
     </class>
     <query name="all.gabarits">From GabaritVO</query>
</hibernate-mapping>


There is no problem to retrieve all the data. In my actionScript, I
instanciate a new dataService object and retrieve all gabarits with
nested gabaritItem's subdata :

ds = new DataService("gabaritvo.hibernate");
ds.addEventListener( DataServiceFaultEvent.FAULT, handleFault );
ds.addEventListener( DataConflictEvent.CONFLICT, handleConflict );
ds.addEventListener(ResultEvent.RESULT, handleResult );
ds.autoCommit = true;
ds.fill( _dataProvider,"all.gabarits",[]);

Now, my goal is to delete all gabaritItem's from the gabaritItems
ArrayCollection and apply the modification directly to the server. I
have tried to simply remove all items from the GabaritVO.gabaritItems
ArrayCollection with a "for" loop and call the removeItemAt( index ) but
there is no change into my DB.

After some search about hibernate features, I have founded the "cascade"
property and apply it like this :

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
         "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd";
<http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd> >
<hibernate-mapping>
     <class name="com.myapp.app.vo.GabaritVO" table="gabarit">
         <id name="id" column="gabaritid">
             <generator class="native"/>
         </id>
         <property name="name" column="gabaritname" />
         <property name="desc" column="gabaritdesc" />

         <set name="gabaritItems" cascade="all,delete-orphan">
             <key column="gabaritid" />
             <one-to-many class="com.myapp.app.vo.GabaritItemVO" />
         </set>
     </class>
     <query name="all.gabarits">From GabaritVO</query>
</hibernate-mapping>


So I have tried the same ActionScript code and this time, LCDS return to
me this kind of error :

(mx.messaging.messages::ErrorMessage)#0  body = (null)  clientId =
"4D2B61F1-F509-9257-F5B1-6928E8C575E8"  correlationId =
"86065E6F-D032-E34E-E217-84C7C6D28DEE"  destination =
"gabaritvo.hibernate"  extendedData = (null)  faultCode =
"Server.Processing"  faultDetail = (null)  faultString = "Could not
invoke sync method on data adapter for destination 'gabaritvo.hibernate'
due to the following error: class
org.hibernate.exception.ConstraintViolationException:Could not execute
JDBC batch update."  headers = (Object)#1  messageId =
"4D2BBF87-7A19-6941-725F-749C171F2B7A"  rootCause = (Object)#2  cause =
(Object)#3  cause = (null)  errorCode = 1048  localizedMessage = "Column
'gabaritid' cannot be null"  message = "Column 'gabaritid' cannot be
null"  nextException = (null)  SQLState = "23000"  updateCounts =
(Array)#4  [0] -3  constraintName = (null)  errorCode = 1048 
localizedMessage = "Could not execute JDBC batch update"  messages =
(Array)#5  [0] "Could not execute JDBC batch update"  [1] "Column
'gabaritid' cannot be null"  SQL = "update gabarititem set
gabaritid=null where gabaritid=? and gabarititemid=?"  SQLException =
(Object)#3  SQLState = "23000"  throwableCount = 2  throwables =
(Array)#6  [0] (Object)#2  [1] (Object)#3  timestamp = 1209113495578 
timeToLive = 0

I don't really understand this error... I made a "delete" operation
(removeItemAt) and LCDS said to me that this is an update... The "update
gabarititem set gabaritid=ull where gabaritid=? and gabarititemid=?" sql
sequence must be "delete from gabarititem where gabarititemid=?" but I
don't know how to do the right things to delete my items. This is an
automatic operation applied by LCDS, so how can I do this operation to
have a correct "delete" sql sequence ??

Any help would be appreciated.

Thanks in advance


Thierry

Reply via email to