While I have been able to find information on how Hibernate's transaction work, so the database doesn't corrupted, it has been harder to understand how Hibernate treats an object which is shared between threads, and each thread tries to save it to the database.
This is my theoretical question:
1) I have a Person object with attributes (ssn, name, address). 2) Three threads have a reference to this person object and each thread calls the method savePersonToHibernate(...)
public void savePersonToHibernate(Person person)
{
...
session.saveOrUpdate(person)
...
}
How does Hibernate cope with 3 threads writing the same object to the storage? Does it put all the transactions in a queue so when the first thread creates the row and identifier (set the id) the remaining two thread will only update it with (in this case) no changes? Or will I actually have the chance of having 2 or 3 rows in the database with a current object only referring to the last identifier created?
I hope it makes some kinda sense... I'm making a queue system, and the data needs to be referred to categories which needs to be created on the fly... and if two or more thread get some data which both needs to have the same category created, I'd hate to have duplicated.
I hope this makes sense... what would you do?