I am trying to get a property value from the class meta data by calling
getPropertyValue(Object object , String propertyName , EntityMode entityMode)
but it is throwing a
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
exception, here is my code:
ClassMetaData metaData = sessionFactory.getClassMetaData(myObject.getClass());
for(String propertyName : metaData.getPropertyNames()){
Object propertyValue = metaData.getPropertyValue(myObject, propertyName, EntityMode.POJO);
System.out.println(propertyValue);
}
It is printing the first object value, and starting from the second run, it is throwing the exception.