How do I use a sequence in Hibernate XML mappings?
The documentation mentions the <generator>
element. However, I want the sequence to be a column instead of an ID.
I know when using Hibernate with Oracle the id in the mapping file is defined something like:
<id name="id" column="item_id">
<generator class="sequence">
<param name="sequence">NAME_OF_YOUR_SEQUENCE</param>
</generator>
</id>
You can also specify the generator class as "native", which is handy if you then switch to an auto incrementing RDMS such as MySQL. The sequence bit is then ignored in MySQL.
Edit: Just re-read your question. I don't think hibernate handles sequences on non-id columns. The general approach I have seen is adding triggers to the table, but it's not a nice solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With