Getting @Id DataType from JPA

I am writing a library that will be used by Hibernate for many types of EJBs via JPA. When loading an EJB from JPA, the library needs the datatype of the fields annotated with @Id. @Id can be annotated to the EJB superclass. Is there a method in Hibernate or JPA that can get the @Id datatype?

I'm tempted to use reflection, but it would require recursion and code that probably already exists in JPA.

+2


source to share


1 answer


If you can go to Hibernate SessionFactory you can call sf.getClassMetaData("Your.Class.Name").getIdentifierType().getReturnedClass()

(remember to check the code you want ;)



+4


source







All Articles