• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get primary key field name from Toplink Entity

 
allareddy suneel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying list down all entities along with primary key fields from my project. I am able to get entity/model class names properly using below mentioned code snippet. I need to get primary key fields from each model but i am getting Database primary key but not java field names. Any help appreciated.


Hashtable descriptors = session.getProject().getDescriptors();
Enumeration descriptorsIterator = descriptors.elements();
TreeMap<String,String> entityMap = new TreeMap<String,String>();
while (descriptorsIterator.hasMoreElements()) {
Descriptor entityObj = (Descriptor) descriptorsIterator.nextElement();
entityMap.put(entityObj.getAlias(), entityObj.getJavaClass().getName());//get the entity name

}

I am using Toplink 9.0.3.
 
James Sutherland
Ranch Hand
Posts: 553
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get the mapping (attribute) for any database field (column) using,

descriptor.getMappingForAttributeName(field).getAttributeName()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic