I am using
@TableGenerator(name="tab",initialValue=2,allocationSize=50)
on Entities and define the ID with
@Id
@GeneratedValue(generator="tab",strategy=GenerationType.TABLE)
private int id;
yet Hibernate still uses 0 as an ID.
I cannot use @GenericGenerator because the annotations do not come with Hibernate4 that ships with Jboss AS7.
Is there a simple solution or do I have to write a custom Generator?
Hibernate is creating ids with id 0
because you have a primitive type. Try using Integer id
instead of int id
. Remember primitives can't hold a null value.
If you want to generate the custom id generator, you can use a SEQUENCE
in DB to generate the id if the object.
<id ....>
<generator class="sequence">
<param name="sequence">YOUR_SEQUENCE _NAME</param>
</generator>
</id>
Read the API about generator classes here.
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