-->
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.  [ 6 posts ] 
Author Message
 Post subject: query using bean field name instead of column name
PostPosted: Mon Oct 11, 2004 2:33 am 
Beginner
Beginner

Joined: Mon Oct 11, 2004 2:22 am
Posts: 41
with the following mapping document in mind, i'd like to be able to search using the following query:
"from BandLevel as bl where bl.id=:id"
however the closest i can get is this:
"from BandLevel as bl where bl.band_level=:id"

so briefly i can't get my query to use the field name of the bean, instead i can only use the column name the field maps to.

Is there a way to make hibernate map the field name?

Hibernate version: 2
Mapping document:
Code:
<class name="BandLevel" table="LU_BAND_LEVELS">
   <composite-id>
      <key-property name="id" column="BAND_LEVEL" type="string" length="8"/>
      <key-property name="companyNo" column="COMPANY_NO" type="string" length="4"/>
      <key-property name="employeeType" column="EMPLOYEE_TYPE" type="string" length="10"/>
   </composite-id>
   <property name="description" type="string" column="DESCRIPTION" length="80"/>
</class>


Name and version of the database you are using:oracle 8


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 11:04 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
i'm trying the same at the moment, because i don't want to use the real-db-column-names in my application.

First i thought this will work automatically ... but it seems not (or, perhaps i'm a little bit stupid ... can be ;) ) ...

To implement an own NamingStrategy won't work i think ... in the next step i will take a look in the EntityPersister ... perhaps i can find there something helpfull ...

or (in the meantime) do you have a better idea?!

gtx
leaner


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 8:18 pm 
Beginner
Beginner

Joined: Mon Oct 11, 2004 2:22 am
Posts: 41
i thought changing my mapping file to this might work, but no:
Code:
<class name="BandLevel" table="LU_BAND_LEVELS">
   <composite-id>
      <key-property name="id"/>
      <key-property name="companyNo"/>
      <key-property name="employeeType"/>
   </composite-id>
   <property name="id" column="BAND_LEVEL" type="string" length="8"/>
   <property name="companyNo" column="COMPANY_NO" type="string" length="4"/>
   <property name="employeeType" column="EMPLOYEE_TYPE" type="string" length="10"/>
   <property name="description" column="DESCRIPTION" type="string" length="80"/>
</class>

when i use "FROM BandLevel as bl WHERE bl.id=:id"
i get the error "path expression ends in a composite value: bandlevel0_.id [FROM package.BandLevel as bl WHERE bl.id=:id ]"

when i use "FROM BandLevel as bl WHERE bl.BAND_LEVEL=:id"
i get the error "could not resolve property: BAND_LEVEL of: package.BandLevel [FROM package.BandLevel as bl WHERE bl.BAND_LEVEL=:id ]"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 12, 2004 1:49 am 
Beginner
Beginner

Joined: Mon Oct 11, 2004 2:22 am
Posts: 41
ok, that 'path expression ends in a composite value' error was because i was using the keyword 'id' for a field name. so now i'm testing with a different field and still getting problems

HQL : FROM BandLevel as bl WHERE bl.companyNo=:companyNo
SQL : select bandlevel0_.id as id, bandlevel0_.companyNo as companyNo, bandlevel0_.employeeType as employee3_, bandlevel0_.BAND_LEVEL as BAND_LEVEL, bandlevel0_.COMPANY_NO as COMPANY_NO, bandlevel0_.EMPLOYEE_TYPE as EMPLOYEE6_, bandlevel0_.DESCRIPTION as DESCRIPT7_ from LU_BAND_LEVELS bandlevel0_ where (bandlevel0_.companyNo=? )
EXC : java.sql.SQLException: ORA-00904: invalid column name

so obviously it doesn't want to map 'companyNo' to it's column name 'COMPANY_NO', so i try that in the HQL:

HQL : FROM BandLevel as bl WHERE bl.COMPANY_NO=:companyNo
EXC : could not resolve property: COMPANY_NO of: com.gunn.etime.jdo.reference.BandLevel [FROM com.gunn.etime.jdo.reference.BandLevel as bl WHERE bl.COMPANY_NO=:companyNo]

so it would seem that the only way i could get this to work would be to change my db field name to 'companyno' or change my field name to 'company_no'.. neither of which are options unfortunately.

i've got no idea where to go from here .. would love some help!!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 12, 2004 3:14 am 
Beginner
Beginner

Joined: Mon Oct 11, 2004 2:22 am
Posts: 41
finally got it working. my mapping file is now this:
Code:
<class name="BandLevel" table="LU_BAND_LEVELS">
   <composite-id>
      <key-property name="code" column="BAND_LEVEL" type="string" length="8"/>
      <key-property name="companyNo" column="COMPANY_NO" type="string" length="4"/>
      <key-property name="employeeType" column="EMPLOYEE_TYPE" type="string" length="10"/>
   </composite-id>
   <property name="description" column="DESCRIPTION" type="string" length="80"/>
</class>

using the HQL: FROM BandLevel as ae WHERE ae.companyNo=:companyNo AND ae.code=:code

and it seems to work now .. so the only difference from the original was that i was using the id keyword as a field name... i'm sure this is something any hibernate expert could have told me from a quick glance.. so thanks experts!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 12, 2004 3:26 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
thanks for your solution!
My mistake was, that i haven't used aliases for my attribute-names. But good to know not to use any fields with name "id" ...

gtx
curio


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