-->
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.  [ 3 posts ] 
Author Message
 Post subject: How i can read hbm.xml from Java
PostPosted: Wed Aug 01, 2007 10:51 am 
Newbie

Joined: Wed Aug 01, 2007 10:36 am
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3

Mapping documents:hbm.xml

Hi i need help to read the hbm.xml of one class.

For example, i have the Foo.java that represents the table FOO from my Database. The Foo.java have a Foo.hbm.xml with the mapping of the table.

Well, i need to read all column-name exactly from tha Database, and the only way that i think is to read the hbm.xml

any suggestions.

Thanxs a lot.

Jorge


Top
 Profile  
 
 Post subject: You Dont Need To
PostPosted: Wed Aug 01, 2007 11:58 am 
Newbie

Joined: Fri Apr 07, 2006 11:29 am
Posts: 17
You will want to use the ClassMetaData which can be accessed from your session factory.

Code:
EntityPersister ep = (EntityPersister)sessionFactory.getClassMetadata(Foo.class);
ClassMetadata cm = ep.getClassMetadata();
String[] properties = cm.getPropertyNames();
List<String> columnNames = new ArrayList();


We get the property names from the class meta data of Foo.class.

Then you will need to figure out what type of mapping it is [SingleTableEntityPersister, JoinedSubclassEntityPersister, UnionSubclassEntityPersister]. For simplicity, I will give the example as follows:

Code:
String columnName;
String tableName;
if(ep.getClass().equals(SingleTableEntityPersister.class))
{
  tableName = ((SingleTableEntityPersister)ep).getTableName();
  for(int i=0, j=properties.length, i<j; i++)
  {
    if(((SingleTableEntityPersister)ep).getPropertyColumnNames(properties[i]).length>0)
    {
      columnNames.Add(((SingleTableEntityPersister)ep).getPropertyColumnNames(properties[i]));
    }
  }
}


Top
 Profile  
 
 Post subject: Works Fine
PostPosted: Wed Aug 01, 2007 5:53 pm 
Newbie

Joined: Wed Aug 01, 2007 10:36 am
Posts: 7
Thanxs a lot, it works perfect.

Jorge


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.