-->
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: How to extract an identifier from a Hibernate object
PostPosted: Tue Jun 19, 2007 4:06 am 
Newbie

Joined: Tue Jun 19, 2007 3:47 am
Posts: 4
Hi,

I am trying to extract id from a Hibernate object without actually knowing the exact type of the object. I found no Hibernate or Spring API so far to give me the identifier of an object.

At the moment I inspect the annotations to find out which field/method is declared with @Id, like this:

Code:
      for (Method m : entityClass.getDeclaredMethods()) {
         if (m.getAnnotation(Id.class) != null) {
            log.debug("id is defined by:" + m.getName());
         }
      }


Knowing the method name I can invoke it on the domain object to extract the identifier from it.

However, I feel there must be a better way - any ideas?

Thanks,

Dusan
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 6:54 am 
Regular
Regular

Joined: Wed May 05, 2004 8:01 am
Posts: 53
I am pretty sure you are looking for this nice utility class:

http://www.hibernate.org/hib_docs/v3/ap ... adata.html

Please rate if that helped.


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.