views:

103

answers:

1

I'm writing a library that will be used to Hibernate many types of EJBs via JPA. When loading an EJB from JPA, the library needs the datatype of the field(s) annotated with @Id. The @Id may be annotated on a superclass of the EJB. Is there a method in Hibernate or JPA that can get the datatype of @Id?

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

+4  A: 

If you can get to the Hibernate SessionFactory you can call sf.getClassMetaData("Your.Class.Name").getIdentifierType().getReturnedClass() (remember to null check that code ;)

Max Rydahl Andersen
Thanks so much. That worked!
User1