I have a DTIMER object which i am loading from a table, then i try to save it to another table in a new Database. the primary key(timer_id) will ALWAYS have a value in it, when i use saveOrUpdate it logically always trys to update the record as the unsaved-value is null
How would i tell it to save Or update the record in the new Table without having to null the primary key on the DTIMER object? if i use unsaved type="ANY' it will always insert and thats not what i want.
I cant find much information in the reference manual on the usage of unsaved-value="ID_VALUE" can anyone explain the usage of this?
Update updates an existing record and save inserts a new record, saveOrUpdate checks then inserts or updates based on the value of the primary key. BUT what happens if you are copying from one table to another and the row in the table you are inserting to is empty BUT the ID key of the object you are inserting is not, Ie ID is not null.
How do i tell it to check the value of the key being held(ID) against the table its inserting into
if you persist an instance with an id, then hibernate thinks it exists and tries to update it. doesn't the saveOrUpdateCopy() method help ? i never used it but the following seems to be what you want:
If the given instance is unsaved or does not exist in the database, save it and return it as a newly persistent instance.
Here is the full text
public Object saveOrUpdateCopy(Object object) throws HibernateException
Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved or does not exist in the database, save it and return it as a newly persistent instance. Otherwise, the given instance does not become associated with the session.
Parameters: object - a transient instance with state to be copied Returns: an updated persistent instance Throws: HibernateException