Hello,
I am trying to map the auto increment column of a table in MySQL database to an id field in the persistent entity and add data. It works fine when a primitive type(say long) is used for id field in the persistent object and I am able to create new records and read them. Now, I am trying to make it work with non-primitive fields for id in the persistent object (please refer to the attached image for id field declaration). Is there a way where we can tell Hibernate how to create the non-primitive object and populate the id value(from database) into it?
AFAIK you can use a UserType
that implements ResultSetIdentifierConsumer
and extract the identity value as well as transform to whatever type you need.
Thank you Christian. I shall try to implement this and update back.
Awesome!! It works great. I used BasicType(as its just a single column) that implements ResultSetIdentifierConsumer. Thanks a lot Christian. I shall post some code snippets for quick ref later on.