Question

In Hibernate 4.x, is there any way to get a list of persistent fields at runtime? By persistent fields I don't mean DB column names, but POJO field names or property names (depending on access type for a particular entity). Also, is there a method to get/set a persistent field's value given a field name as a string, regardless of whether it's a field or property name?

Was it helpful?

Solution

It seems that everything I need (and more) is contained in ClassMetadata class (documentation).

I can get the metadata for a particular class by using SessionFactory.getClassMetadata(entityClass) and then use metadata.getPropertyNames(), etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top