I want to use MetaData to retrieve properties information .
Here is an exemple of one persitant class :
Code:
@Entity(access = AccessType.FIELD)
@Table(name="rightapplication")
public class Right extends BaseEntity {
private String description;
@Column(unique = true)
private String name;
...
}
Each classes extend of BaseEntity :
Code:
@Entity(access = AccessType.FIELD)
@Inheritance(strategy=InheritanceType.JOINED )
public class BaseEntity implements Serializable {
@Id(generate = GeneratorType.AUTO )
private Long id;
@Version
private Long version;
@ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE},
mappedBy="sources")
@OrderBy("startDate")
private List<Event> events;
@OneToMany(cascade = CascadeType.ALL ,
mappedBy = "baseEntity")
...
Code:
Code:
Map classesMetadata = sessionFactory.getAllClassMetadata();
for(Object obj : classesMetadata.keySet())
{
(ClassMetadata)classesMetadata.get(obj);
try
{
System.err.println("Class : " + obj);
String[] strings = persiter.getPropertyNames();
for(String string : strings)
{
Object object = persiter.getPropertyValue(entity, string, EntityMode.POJO);
System.err.println("Valeur : " + classesMetadata.get( object ));
}
}
catch(HibernateException e)
{
System.err.println("Exception");
e.printStackTrace();
}
And I have this exception (for each persitant classes) :
Full stack trace of any exception that occurs:Code:
Class : fr.umlv.ir3.emagine.user.profile.Right
Valeur : null
Valeur : null
Valeur : null
Valeur : null
Exception
org.hibernate.PropertyAccessException: could not get a field value by reflection getter of fr.umlv.ir3.emagine.user.profile.Right.description
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:35)
at org.hibernate.tuple.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:270)
at org.hibernate.tuple.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:280)
at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:3251)
at fr.umlv.ir3.emagine.util.HibernateUtils.getPropertySnapShot(HibernateUtils.java:129)
at fr.umlv.ir3.emagine.Main.main(Main.java:37)
Caused by: java.lang.IllegalArgumentException
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18)
at java.lang.reflect.Field.get(Field.java:357)
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:32)
... 5 more
Hibernate version: 3.1rc2
Name and version of the database you are using:PostgreSQL 8.0.4
Any Idea ?