Hibernate and Postgresql - generator class in hibernation mapping file

The IDs in my postgresql database are auto-incremental (sequences are defined in the database). When creating hibernate mapping files, I install a class generator to increase:

<class name="model.Names" schema="public" table="names"> <id name="id" type="int"> <column name="id"/> <generator class="increment"/> </id> 

However, I keep getting all kinds of errors (null pointer exception, org.hibernate.TransactionException: transaction did not start successfully), so I first wanted to make sure that this is the correct generator class before debugging and finding errors elsewhere. I tried the sequence (does not work at all, the increment works in some cases). The application is written in JSF 2.0.

Thanks in advance for any suggestions.

Best regards, Insolence.

+1
source share
1 answer

If you want to use sequences, you should definitely use one of sequence or seqhilo if you want hi / lo algorithm generators. The problem is that โ€œdoes not work at allโ€ does not at all help to understand what problems you are facing.

Just in case, here is a snippet for the sequence generator:

 <id name="id" type="long" column="person_id"> <generator class="sequence"> <param name="sequence">person_id_sequence</param> </generator> </id> 

And for the seqhilo generator:

 <id name="id" type="long" column="cat_id"> <generator class="seqhilo"> <param name="sequence">hi_value</param> <param name="max_lo">100</param> </generator> </id> 

If you want to find out why it โ€œdoesnโ€™t work at allโ€, I suggest turning on the generated SQL logging to see what happens.

Also note that PostgreSQL supports the identity generator (see HB-875 and HHH-1675 ) when using SERIAL or BIGSERIAL columns.

References

+2
source

All Articles