aspose file tools*
The moose likes Object Relational Mapping and the fly likes Get primary key field name from Toplink Entity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Get primary key field name from Toplink Entity" Watch "Get primary key field name from Toplink Entity" New topic
Author

Get primary key field name from Toplink Entity

allareddy suneel
Greenhorn

Joined: Sep 18, 2012
Posts: 13
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

Joined: Oct 01, 2007
Posts: 553
You can get the mapping (attribute) for any database field (column) using,

descriptor.getMappingForAttributeName(field).getAttributeName()

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get primary key field name from Toplink Entity
 
Similar Threads
entity beans deployment descriptors
Entity beans which map two tables with foreign key pointing to alternate key (not primary key)
primary key
needs clerification from chapter 6 Entity Bean Synchronization
ejbcreate return type