-->
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.  [ 2 posts ] 
Author Message
 Post subject: ClassMetadata.getPropertyValue Returns NULL
PostPosted: Wed Dec 09, 2009 10:29 am 
Newbie

Joined: Thu Aug 13, 2009 9:58 am
Posts: 5
I have a class such as:

Code:
public class A implements Serializable{
   
   ........
   
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "COLUMN_ID")
   private B b;

             ........
}

public class B implements Serializable{
   
             ........

   @Column(name = "B_NAME", nullable = false, length = 135)
   private String name;

             ........
}


If I try:
Code:
a.getB().getName()


The correct value is returned. What I'm trying to do though is match the property values with elements in an XML file. So for this I thought to use ClassMetadata.getPropertyValue. However,

Code:
SessionFactory factory = HibernateUtil.currentSession().getSessionFactory();
ClassMetadata classMetadata = factory.getClassMetadata(HibernateUtil.currentSession().getEntityName(a.getB()));
Object value = classMetadata.getPropertyValue(a.getB(), "name", EntityMode.POJO);   


returns a NULL value. ClassMetadata.getPropertyNames() does return all the list of properties. I've tried Hibernate.initialize(a.getB()) and that didn't work either.

Am I using the getPropertyValue method incorrectly? Am I doing something else wrong?

Thanks for the help.


Top
 Profile  
 
 Post subject: Re: ClassMetadata.getPropertyValue Returns NULL
PostPosted: Tue Dec 22, 2009 11:27 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
Quote:
I have the same problem. How do you use getPropertyValue() to get the value?

I am also passing in a valid object, a String for the propertyname and the EntityMode.POJO.


I thought I had the same problem, but in fact it worked and I had just not set the fields before...


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

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.