Hi,
I'd like to use a custom type for an id field, that's represented as an INTEGER in the database.
I can't seem to get Hibernate to cope with this, as it's expecting either an Integer, Long, String, etc. in the case of auto-generated id assignment.
Is there a way I can do this without having to write a setID(Integer id) { this.id = new MyIDClass(id); }
method?
My custom type is basically just a wrapper around an Integer, and it has the appropriate custom type defined and used for Hibernate.
It extends org.hibernate.type.IntegerType, but if I override the public Class getReturnedClass() method to return say MyIDClass.class, it throws the error that says it was expecting an integer, long, string, etc....
But if I return Integer.class from that method, it goes fine until it expects a setter like setID(Integer id).
So is there a way to tell Hibernate to work with custom id types for auto-generated values, and can someone explain how?
Thanks,
David
|