-->
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.  [ 1 post ] 
Author Message
 Post subject: NonUniqueObjectException + Inheritance
PostPosted: Fri Nov 26, 2010 4:41 am 
Newbie

Joined: Tue Mar 02, 2010 4:28 pm
Posts: 8
Hi!
I'm getting the non unique object exception in a bit complex environment, so i'll try to make it clear.
I have a parent class P, and three inheriting classes P1, P2, P3 and the inheritance is declared like :
Code:
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@DiscriminatorColumn(name="entityType", discriminatorType=DiscriminatorType.STRING)

I overrode the equal and hash methods to make the distinction between two objects with the same id in the same session.
ids are assigned manually using an incremanetal counter for each child entity: thus, I may have P1[id=1] , P2[id=1] and P3[id=1] in the same session.

The aim of this class is to integrate and index(lucene) a csv file into a database, fill a Main table(Person), and fill annex tables(state, city, ...).
Those annexe tables are P1, P2, P3 inherting from a generic class AnnexEntity which is P in our context. I'm using the same DAO to manage the three entities.

The scenario i'm using for data migration :

0/ open the long transaction
1/ read a Line from the csv file
2/ insert the person objects
3/ extract city, state , zip ,... objects and assign an id for each one
4*/ continue till the end of the file
5/ commit the long transaction

I found one workaround , but i'm looking for a better one. the sol is to assign ids with one counter, means i'll have holes in ids for each table.
Any other suggestions.
Thanks in advance.


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

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.