-->
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.  [ 1 post ] 
Author Message
 Post subject: Propery way to determine columnname for sqlRestriction?
PostPosted: Thu Apr 14, 2005 2:13 pm 
Newbie

Joined: Thu Apr 14, 2005 1:23 pm
Posts: 3
Trying to construct in code a Restrictions.sqlRestriction of the form:

Restrictions.sqlRestriction("upper({alias}." + fieldName + ") > Smith");

where the fieldName variable contains a property name.

This works fine so long as the property name is identical to the column name. If not, I get errors such as the one listed below. For a general solution, fieldname needs to be columnName.

My questions then are: (1) is my understanding of sqlRestriction's needs correct and if so (2) what is the proper way to retrieve the column name for the desired property name?

What I have so far is:

Code:
private String getColumnName(String fieldName) {
   SessionFactory pmf = session.getSessionFactory();
   ClassMetadata meta = pmf.getClassMetadata(Corporate.class);
   String[] cols = ((BasicEntityPersister)meta).toColumns(fieldName);
   return cols[0];
}


which seems to work.

Am I on the right path? Is there a better way to do this? Are there any problems with this approach?

Thanks,
Gerald


Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:
<property
name="corpName"
column="CORP_NAME"
/>


Full stack trace of any exception that occurs:
Hibernate: select this_.CORPORATE_ID as CORPORATE1_0_, this_.CITY as CITY1_0_, this_.CORP_NAME as CORP3_1_0_, this_.HQ_ADDRESS1 as HQ4_1_0_, this_.HQ_ADDRESS2 as HQ5_1_0_, this_.STATE as STATE1_0_, this_.TAX_NUMBER_FED as TAX7_1_0_, this_.TAX_NUMBER_STATE as TAX8_1_0_, this_.ZIP as ZIP1_0_ from CORPORATE this_ where (lower(this_.corpName) = 'intel') order by this_.CORP_NAME asc
2005-04-14 10:29:34,360 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 904, SQLState: 42000
2005-04-14 10:29:34,360 [main] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-00904: "THIS_"."CORPNAME": invalid identifier


Name and version of the database you are using: Oracle10g

Code:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.