-->
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.  [ 12 posts ] 
Author Message
 Post subject: joined-subclass and optimistic-locking with version
PostPosted: Thu Feb 17, 2005 7:07 pm 
Newbie

Joined: Tue Feb 08, 2005 11:34 am
Posts: 5
Hi
Hibernate version:
2.1.8

Mapping documents:
Extra attributes left out ...
Code:
<hibernate-mapping>
   <class name="OrderHeader" table="CMOHDP" schema="CDTA111">
        <id name="ohdId" column="ID_OHD" type="int" unsaved-value="0">
            <generator class="identity"></generator>
        </id>
        <version name="version" type="integer" column="RECVER"/>
        <property name="cliNo" type="int" column="CLI_NO"/>

        <joined-subclass name="SheetOrderHeader" table="CMSOHP"   
          schema="CDTA111" >
            <key column="ID_OHD"/>
            <property name="palletStyle" type="java.lang.String"column="PALLET_STYLE"/>
        </joined-subclass>
    </class>
</hibernate-mapping>


Name and version of the database you are using:
DB2 on AS/400 V5R2

I have a table schema as such:
Table A
ID_OHD INTEGER -- PK (Indentity type)
RECVER INTEGER -- Used for optimistic locking
CLI_NO -- Arbitraty field

Table B
ID_OHD INTEGER -- PK, FK (refering to TABLE A.ID_OHD)
RECVER INTEGER -- Used for optimistic locking
PALLET_STYLE -- Arbitraty field

These tables can be modified by an external source such as an RPG program.

Table B has a one-to-one mapping with table A (Table A being the master)

I have mapped this as a joinned subclass (OrderHeader being an abstract base class).
My problem is that I cannot define a <version> element inside the <joined-subclass> element.
However I do require that on update the A.RECVER as well as B.RECVER be included in their corresponding statements.

Is there another way to map this. I cannot change the tables but I can let go of the AbstractBaseClass and SubClass notion and create a composite...

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 18, 2005 11:58 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
I solved the same problem with an Interceptor.

Every time an Instance of SheetOrderHeader is changed the Interceptor increments its RECVER which is maped as an ordinary property.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 18, 2005 12:35 pm 
Newbie

Joined: Tue Feb 08, 2005 11:34 am
Posts: 5
Thanks for the quick answer.
However by mapping the subclasse's RECVER as a simple property hibernate will not add the verification of the B.RECVER's value in the WHERE clause:
WHERE B.RECVER = {old_b_table_recver_value}
Thus I won't be able to rely on this columns value for optimistic locking purposes
(unless I check it in the application which is not an alternative in my case).

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 20, 2005 5:42 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Ups! Yes you're right. I did not thing about that.

If Hibernate 3 is an option for you, you could add your own SQL for update and delete and add the where clause.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 1:29 pm 
Newbie

Joined: Tue Feb 08, 2005 11:34 am
Posts: 5
Thanks I'll look into that.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 8:54 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Or file a feature request in the JIRA Issue Tracking. IMHO to make joined-subclass and optimistic locking with versioning usefull toghether with 3rd party apps this is a must have.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 9:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Guys, updates to the joined-subclass table ALWAYS result in an increment of the version number on the root class table.

So optimistic locking works just fine for joined-subclass mappings.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 5:27 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Hi Gavin

The behaviour on the root class table is fine.

The problem is the joined-subclass table which cannot have its own version id. We have a legazy application which I cannot change and which touches the joinded-subclass table only. Having an independant version id for the joined-subclass table could solve this problem.

As a workaround it's of course possible to map this as 1:1 relation, or do some more work with an interceptor and hand writen SQLs.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 6:42 pm 
Newbie

Joined: Tue Feb 08, 2005 11:34 am
Posts: 5
Hi all, thanks for the feedback.

I agree with Gavin from an object point of view it makes sense to have 1 version property for a given entity. However from an SQL standpoint an entity composed of multiple rows (from multiple tables) should have a way of discovering if a particular row changed.

I looked into an alternative which I was not so hot about from a performance standpoint, which consisted of using the optimistic-lock="all".
But this is not supported when joined-subclasses are used.

I tried the <join> element in hibernate 3 but it does not support nested <set> elements which I do need.

I've tried custom SQL with the <sql-insert> element adding the "AND RECVER = ?" statement in the WHERE CLAUSE.
My problem is that Hibernate doesn't know there is an extra parameter marker in the SQL statement and has no way of setting a value for it so I get a SQLException.

The one-to-one mapping does represent an alternative however from an Object Model perspective this does not yield an object graph that makes sense.

In my case the base table is an Order and the joinned subclass (and its table) represents a sheet order.
In some time new types of orders will be added and I do have a column that can be used as a discriminator in the base table however all subclasses will be joined subclasses as I cannot use the table-per-class-hierarchy mapping (cannot change the base table).

Is there an option I don't know about that could help solve my problem.

From an object model perspective I could use a Composite which would contain both the "Order" and "SheetOrder" objects. However in order to have this work in hibernate I would need to create a new table which would contain the foreign keys to the two tables mentionned earlier. I'm not sure I can get this done as I don't have all the freedom I would want in the DB schema.

I'll keep looking but I'm running out of ideas.

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 11:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It should be possible to write a custom persister to do this.

Not trivial. But possible.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 3:25 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Quote:
I've tried custom SQL with the <sql-insert> element adding the "AND RECVER = ?" statement in the WHERE CLAUSE.
My problem is that Hibernate doesn't know there is an extra parameter marker in the SQL statement and has no way of setting a value for it so I get a SQLException.


What about a stored procedure?

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 12:32 pm 
Newbie

Joined: Tue Feb 08, 2005 11:34 am
Posts: 5
That would be one of my final alternatives.
However, Im not too crazy about having to make stored procedures to accomplish this kind of task. Each time I would have this situation I would have to create a new stored proc.

Also I'm not quite sure how to do this in a clean way as the value of the RECVER would be incremented by the stored procedure ... thus hibernate would have to retrieve the RECVER's new value from the stored procedures output parms somehow and update the in memory entity.

I'm not quite sure how to go about this.
I looked at the Interceptor interface but it doesnt seem to offer the appropriate hook.


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