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: getting objects property column name
PostPosted: Fri Jan 13, 2006 4:51 am 
Beginner
Beginner

Joined: Wed Nov 23, 2005 12:55 pm
Posts: 23
Hey,

I was searching in the API docs how to retrieve an Objects property metadata.

I already read this http://forum.hibernate.org/viewtopic.ph ... ame+object

But according the EntityPersister may have changed because there is no getTable or what soever in their
http://www.hibernate.org/hib_docs/v3/ap ... ister.html

I have several object with different properties, these properties have a 1 to 1 mapping to a column name.
--- object --------------------- COLUMN
so Customer.getName() --> C_NAME

Now there's a stored procedure someone wrote that I have to access using plain jdbc and one of the in parameters is the actual columname.
So I wanted to know how I can get the C_NAME from the customer name property.

My best guess was using the ClassMetaData, but I can't seem to find the reference to the Xml Mapping.

Anybody got an idea?


Top
 Profile  
 
 Post subject: Is this the right way
PostPosted: Fri Jan 13, 2006 5:13 am 
Beginner
Beginner

Joined: Wed Nov 23, 2005 12:55 pm
Posts: 23
I found this somewhere on the forum, but no replies to his request:
http://forum.hibernate.org/viewtopic.ph ... columnname

SessionFactory factory = session.getSessionFactory();
ClassMetadata metaData = factory.getClassMetadata(Customer.class);
BasicEntityPersister persister = (BasicEntityPersister)metaData;
String[] columns = persister.toColumns("creationDate");
for(int i=0;i<columns.length;i++){
this._logger.info("column name "+columns[i]);
}

It seems to work, can somebody explain me why I have to downcast to the BasicEntityPersister, why not promote the toColumns to the metaData? Would be more obious imho.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.