Expand my Community achievements bar.

insert / delete problems using FDS with hibernate

Avatar

Level 1
Hi everyone,



I'd be very thankful if anyone could help me with this
problem because I got stuck on it for several weeks.



I'm developing a FDS application with database connection
and I've mapped a relational database to POJO's with Hibernate
(using hibernate tools). I'm experiencing a lot of problems when I
try to insert and delete items using the hibernate assembler. Here
is my situation.



My database, which represents information about cars,
contains five tables:



MODEL

id

engine

transmission

cab

bed



MODEL_PACK

model_id

pack_id

inclusion_type



PACK

id

name

category



MODEL_COLOR

model_id

color_id



COLOR

id

extColor

intColor



The AS classes that represent this schema:



Model.as



id:int;

engine:string;

transmission:string;

cab:string;

bed:string;

colors:ArrayCollection;

packs:ArrayCollection;





ModelPack.as



id:ModelPackId;

model:Model;

pack:Pack;

inclusion:String;



ModelPackId is a custom class to store the composite primary
key which is mapped to the corresponding java POJO.





Pack.as



id:String;

category:String;

name:String;

models:ArrayCollection;





Color.as



id:String;

extColor:String;

intColor:String;

models:ArrayCollection;







The corresponding destinations in data-management-config.xml:



<destination id="models.hibernate">

...........

<many-to-many property="colors"

destination="colors.hibernate" lazy="false"/>

<one-to-many property="packs"

destination="ModelsPacks.hibernate" lazy="true"/>

..............................





<destination id="colors.hibernate">

.............................

<many-to-many property="models"

destination="models.hibernate" lazy="true"/>

....................................





<destination id="ModelsPacks.hibernate">

....................

<identity property="id"

type="com.fds.proyecto.hibernate.ModelPackId"/>

<many-to-one property="model"

destination="models.hibernate" lazy="true"/>

<many-to-one property="pack"

destination="packs.hibernate" lazy="true"/>

...................





<destination id="packs.hibernate">

...................

<one-to-many property="models"

destination="ModelsPacks.hibernate" lazy="true"/>

.....................





As you can see the relationships are bidirectional.



For example I have the data service to manage the operations
in the front end and a datagrid:



<mx:DataService id="models_ds"
destination="models.hibernate" result="handleResult(event)"/>



<mx:DataGrid id="modelList"
dataProvider="{models_ac}"/>



and a button:



<mx:Button label="Delete" id="btnDelete"
click="delModel()"/>



The callback function only uses the hibernate assembler to
delete the model:



models_ds.deleteItem(modelList.selectedItem);

models_ds.commit();



It seems that the operation is performed succesfully but
then when I check the database or reload the application the model
that I've tried to delete is still there with its corresponding
packs and colors. Sometimes the application throws a runtime error
about synchronization. I've tried to remove the relations in the AS
classes because I think that the problem have to do with the
relations between classes and it works but in this case the
application doesn't meet my requirements and the delete operation
is more complex. Similar problems happen when I try to add Items.



I've tried a lot of solutions to fix that problem (remove
relations, convert them to unidirectional instead of
bidirectional...) and I'd be deeply grateful if anyone can show me
the procedure to add and delete items in that scenario. I've also
thought that I could have missed any tag like "cascade" in the
hibernate mapping files but I haven't tried this solution because I
don't know what does it exactly mean.



I have heard that the hibernate assembler has some bugs and
in some circumstances it doesn't work properly. Could anyone
confirm that?If true what should be the alternative solution? It's
very important for me because this is a small part of my
dissertation and I can't continue because I got stuck on this
issue.



Thanks a lot in advance,



Carlos
0 Replies