I had some trouble about detached objects and getting them attached again to a new session. I merged them, but the associations (objects in a set) were not updated automatically. As a result a query delivered new objects with the data instead of giving me the existing objects. Therefore I decided to do the loading by myself and instead of using associations to write the IDs and parentIDs by myself. By I had no success so far. I would like to let Hibernate generate the database and need to have the proper constraints.
My tries: 1. In the first place I tried to work with one session (single user environment). Hibernate would work only with valid (unique) references in that case. But in case an exception occurs the session is not really valid any more. So I couldn't avoid to reattach all my objects..
2. I tried to add "manually" a foreign constraint via <database-object>. But the SQL was not executed.
3. I tried <many-to-one name="parentId" column="PARENTID" class="Parent" not-null="true" />. The foreign constraint was created as I could see in the logs, but I had to make parentId of type "Parent". I couldn't use the type long for parentId, because I got some strange exceptions at saving. I would really appreciate to avoid these associations, because I know they are not valid.
Did I miss anything?
Thanks.
|