-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ClassMetaData
PostPosted: Sat Nov 26, 2005 3:25 pm 
Newbie

Joined: Sat Nov 26, 2005 2:14 pm
Posts: 1
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 ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.