Hi all,
I'm supposed to integrate a legacy database powered by Firebird with a new system and of course I'm planning to use Hibernate. The the database generates primary keys using a combination of generator + trigger which is fired before insert to overwrite user supplied PK values with the next value from the appropriate generator.
I mapped the id as:
Code:
<id name="Nr"
column="NR"
type="integer"
>
<generator class="increment"/>
</id>
and the code that inserts new rows into the table is:
Code:
...
try {
s = getSession();
t = s.beginTransaction();
Serializable rtn = s.save(obj);
t.commit();
return rtn;
}
catch (HibernateException e) {
if (null != t) t.rollback();
throw e;
}
...
The whole thing seems to work, but the potential issue I'm affraid of is concurrency.
Is the approach safe so that I can be sure that I won't end up with for example three identical PK values returned to three different threads as Hibernate seems to read the max values from the table and then inserts rows (or in reverse order, firstly inserts and then reads values)??
Thanx in advance for any help.
Regards
Chris