Beginner |
|
Joined: Tue Sep 14, 2004 1:03 pm Posts: 33 Location: Calgary, Alberta Canada
|
OK, I guess I'll have to answer my own post. It seems on doing a seach that this is somewhat of a problem. Unfortunately there are never any soulutions posted or even any further probing for information.
My guess is (and it is a gues because I have come up with a kluge to the problem and have not tested this theory yet) is that there is a problem with the equalsto and hashcode. Without these methods properly implemented there will be issues with database idenity with objects.
What I beleive is happening is that this is a web based application. In some instances the sessions is being closed causing a dereferencing between the object in memory and the object as it is stored in the database. Therefore Hibernate thinks it is a new object that has the same primary key as an object stored in the database. Therefore it assignes the next available key (Hibernate is manageing my keys) to the object and stores it in the database.
So what needs to be done is to implements the equalsto and hashcode methods so that Hibernate knows that we are talking about the same object in the database and it can reassociate these in my new transaction. (I will be testing this at a later date)
My kluge was to add an attribute to the many object in my many-to-one association that will be the forign key(FK) to the one. The object itself is mapped but I have set the update and insert to false on the many to one mapping and just mapped the FK as a regular attrubute and set it in my Data Access Object (DAO). Hibernate can then recreate the object easily and does not mess things up when i persist the new objects. (its ugly but it works)
|
|