-->
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: How I can write an HQL using a Component property?
PostPosted: Fri Jan 07, 2005 2:54 pm 
Beginner
Beginner

Joined: Fri Jan 07, 2005 2:47 pm
Posts: 45
Hibernate version:
Hibernate2

Mapping documents:
none

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

done

Debug level Hibernate log excerpt:


MY QUESTION:

This is my User.hbm.xml file. I need to get the user information using the username as the criteria. Since the username is a property of the Password class how do I write the native SQL show below to an HQL???

When I tried the following HQL
(List finds = session.find("from User user where user.username = username");
query.setString("username", username);

I got an error saying that the username is not a property of the User class. Can you help????

Native SQL:

Select *
from x_requestors
where x_requestors.username = 'username'


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
package="SAP.BusinessObjects"
default-cascade="save-update">

<class name="User" table="X_REQUESTORS">

<id name="userid"
column= "REQ_ID"
type="java.lang.String"
length="20">
<generator class="SAP.DAOObjects.SeqGeneratorUser"/>
</id>

<property name="lastname"
type="java.lang.String"
length="50"
not-null="true"
column="LAST_NAME"
update="true"
insert="true"/>

<property name="firstname"
type="java.lang.String"
length="50"
not-null="true"
column="FIRST_NAME"
update="true"
insert="true"/>

<component name="pswd" class="Password">
<property name="password"
type="java.lang.String"
length="100"
not-null="false"
column="PSWD"
update="true"
insert="true"/>

<property name="username"
type="java.lang.String"
length="10"
not-null="false"
column="USERNAME"
update="true"
insert="true"/>
</component>

<component name="address" class="Address">
<property name="email"
type="java.lang.String"
length="25"
column="EMAIL"/>
</component>

<many-to-one name="site"
class="Site"
cascade="all"
column= "PRIM_LOC" />

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 07, 2005 3:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
user.pswd.username


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