I'm using hibernate and most of the time I want it to set the ID for me. But, for one particular object I want to sometimes force it to use an ID of my choosing.
Keep in mind that 99% of the time I want this object to do what it's doing. But I'd like to know how to override this behavior in a few cases.
Here is the ID column specified in the hbm file:
<id column="id" name="id" type="integer">
<generator class="sequence"><param name="sequence">Forum_id_seq</param></generator>
If I do:
then it will save a value to the DB which has a value in the ID that comes next in the Forum_id_seq sequence. It isn't the value I specify in the call to setId.
If I then immediately then do this:
then it throws an exception saying something like:
identifier of an instance of com.knowlist.list.hh.ForumRecord altered from 1024 to 32
Given that this is relatively rare, I'm tempted to just revert to JDBC to change the ID to what I want it to be. But I'd first like to know if there's a way to do this within hibernate.