-->
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.  [ 3 posts ] 
Author Message
 Post subject: Optimistic locking: increment the version of a parent object
PostPosted: Mon Feb 07, 2005 2:43 pm 
Newbie

Joined: Mon Feb 07, 2005 2:08 pm
Posts: 1
Location: La Plata
It is not an error. It is just a question. How could i increment the version of a parent object when the version of one of its child objects is incremented. I need it to get an optimistic locking at the parent level and not just at child level. For example suppose a bill having many items. When a user modify an item and save the bill, the traditional behaviour is just increment the item version. In addition, i want to increment the bill version to keep the optimistic locking at bill level. Thanks a lot.

Hibernate version: 2.1.6

Mapping documents:
The parent object mapping document

<?xml version="1.0" encoding="WINDOWS-1251"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="ar.gov.mecon.esidif.domain.pagos.FacturaEscenarioPago" table="FACTURA_ESCENARIO_PAGO">
<id name="id" column="ID" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<version name="version" column="VERSION" />
<many-to-one name="factura" column="ID_FACTURA" not-null="true" />
<many-to-one name="medioPago" column="ID_MEDIO_PAGO" not-null="true" />
<many-to-one name="cuentaCobradora" column="ID_CTA_COBRADORA" />
<many-to-one name="cuentaPagadora" column="ID_CTA_PAGADORA" />
<list name="itemsEscenarioPago" lazy="true" cascade="all-delete-orphan" access="field">
<key column="ID_FACTURA_ESCENARIO_PAGO" />
<index column="IDX" />
<one-to-many class="ar.gov.mecon.esidif.domain.pagos.ItemEscenarioPago" />
</list>
</class>
</hibernate-mapping>

Child object mapping document

<?xml version="1.0" encoding="WINDOWS-1251"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="ar.gov.mecon.esidif.domain.pagos.ItemEscenarioPago" table="ITEM_ESCENARIO_PAGO">
<id name="id" column="ID" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<version name="version" column="VERSION" />
<property name="importe" type="double" column="importe" not-null="true" />
<many-to-one name="itemFactura" column="ID_ITEM_FACTURA" not-null="true" />
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: Oracle 10g

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: Interceptor callback
PostPosted: Mon Feb 07, 2005 3:43 pm 
Newbie

Joined: Tue Dec 14, 2004 2:57 pm
Posts: 12
I suppose an easy way would be to use Interceptor.findDirty, and have it mark the child id field as dirty if the child is dirty.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 9:59 am 
Newbie

Joined: Fri Dec 30, 2005 9:19 am
Posts: 3
Location: Buenos Aires
I am trying to find a solution for this issue too. According to Hibernate Doc a collection will only be marked as dirty when an item is added or removed, but not when an item is modified.
I need to increment the parent version even when an item in one of its collections of children is modified. This doesn't happen automatically in Hibernate and I haven't found any "nice" way to tell Hibernate to do it.
currently i am thinking of 2 possibilities:
1) Configure an Interceptor and implement findDirty() returning the index of the collection property in the parent when a change in the state of any child was detected. Problems or difficulties of this approach:
- Im forced to reimplement the same logic already provided by hbm, just changing slightly its behaivour (i don't like it!). Is this a feature not present in Hbm or is there any way to do it but just not documented ?
2) Extend Hbm's DefaultFlushEntityEventListener and override dirtyCheck() to perform this check as I want. Then configure Hbm to call the extended listener instead of Hbm's default when the flush event occurs. I should check the instance lifetime of a listener in Hbm...instances of listeners are created whith every new session ?

I like the second option better than the first one.

Has anyone already found a decent solution for this problem ? thanks a lot !!

Offtopic for mbutti:
****************
Mati, no me propongas la columna de second_level_version en la factura porque no puedo tocar las tablas del modelo más allá de agregar la col de version y listo !! (limitaciones del proyecto).

Saludos para la banda del Mecon !!

_________________
Gabi Baños
Hexacta Inc.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.