OK, so you have your strongly typed values, but how can you generate them so they can be used as a numeric primary key?
Assuming you set up your typed ids as in: Using Typed Id Values With Hibernate, you don't have to do much to make them from sequences.
This example uses oracle sequences, but I'm sure the method applies to other stuff too.
Annotate your class to use custom sequence generator
This uses the hibernate-specific @GenericGenerator annotation.
"Using an hbm file"
Implement your sequence generator
Just delegate to the original implementation to get the number, then strongly type it.
Labels:
3 Comments
Hide/Show CommentsFeb 08, 2011
Anonymous
hi, when I run this constructor is null @constructor = type.getReturnedClass().getConstructor(Long.class);
any help please?
Feb 09, 2011
James Richardson
Unfortunately all these things need to be configured right, otherwise you will get odd errors.
Check that getReturnedClass returns your expected class, and that it has a public constructor of type long as documented in the other article. Also make sure that you are using lower case long in the getConstructor call.
Feb 09, 2011
James Richardson
Also bit surprised that it is null, as getConstructor is not supposed to return null..... I suppose that it is possible hibernate have changed the class structure in a more recent version... Can you check the configure method is actually being called?
Add Comment