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.