I have a j2ee application using hibernate with annotation. How do I annotate the Id field in my pojo class to set it as auto increment or auto generated. and in adding the bean do I leave that field in my bean null?
Java – Hibernate Auto Increment ID
auto-incrementhibernatejava
Related Topic
- Java – How to use java.net.URLConnection to fire and handle HTTP requests
- Java – a JavaBean exactly
- Sql – Reset auto increment counter in postgres
- Sql – How to set auto increment primary key in PostgreSQL
- Java – Why is the Spring @Autowired field null
- Java – Why is printing “B” dramatically slower than printing “#”
Best Answer
and you leave it
null
(0
) when persisting. (null
if you use theInteger
/Long
wrappers)In some cases the
AUTO
strategy is resolved toSEQUENCE
rathen than toIDENTITY
orTABLE
, so you might want to manually set it toIDENTITY
orTABLE
(depending on the underlying database).It seems
SEQUENCE
+ specifying the sequence name worked for you.