-->
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.  [ 8 posts ] 
Author Message
 Post subject: HQL help
PostPosted: Tue Jun 12, 2007 3:47 pm 
Newbie

Joined: Wed May 30, 2007 4:14 pm
Posts: 15
Trying to write a query to get a user by email address. I have the following and am getting the error below:



Hibernate version: 3.2.3

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping schema="DBO_FSOL">
<class name="com.futuresoldiers.struts.form.TempRegistrationForm" table="USERNAME">
<id name="tempUserId" type="long" column="USERNAME_ID">
<generator class="com.futuresoldiers.dao.hibernate.TriggerAssignedIdentityGenerator"/>
</id>
<property name="emailAddress" type="string" column="EMAIL_TX"/>
<property name="firstName" type="string" column="FIRST_NAME_TX"/>
<property name="lastName" type="string" column="LAST_NAME_TX"/>
<property name="status" type="string" column="STATUS_CD"/>
<property name="dateOfBirth" type="date" column="DOB_DT"/>
<property name="createdByUser" type="string" column="CREATE_BY"/>
<property name="modifiedByUser" type="string" column="MOD_BY"/>
<join table="ADDRESS">
<key>
<column name="USERNAME_ID" not-null="true"/>
</key>
<property name="address1" type="string" column="ADDRESS1_TX"/>
<property name="address2" type="string" column="ADDRESS2_TX"/>
<property name="city" type="string" column="CITY_TX"/>
<property name="state" type="string" column="STATE_CD"/>
<property name="zipCode" type="string" column="ZIP_CD"/>
<property name="createdByAddress" type="string" column="CREATE_BY"/>
<property name="modifiedByAddress" type="string" column="MOD_BY"/>
</join>
</class>
</hibernate-mapping>


CODE
temp = (TempRegistrationForm) session.createQuery("select\n" + "UN.USERNAME_ID,UN.EMAIL_TX,UN.FIRST_NAME_TX,UN.LAST_NAME_TX,\n" + "UN.STATUS_CD,UN.DOB_DT,AD.ADDRESS1_TX,AD.ADDRESS2_TX,\n" +
"AD.CITY_TX,AD.STATE_CD,AD.ZIP_CD\n" +
"from\n" +
"DBO_FSOL.USERNAME UN,\n" +
"DBO_FSOL.ADDRESS AD\n" +
"where UN.USERNAME_ID=AD.USERNAME_ID\n" +
"and UN.USERNAME_ID=" + emailAddress)
.uniqueResult();


ERROR
stdout: - building session factory
[12/Jun/2007:15:46:48] info ( 1113): CORE3282: stdout: - Not binding factory to JNDI, no JNDI name configured
[12/Jun/2007:15:46:49] info ( 1113): CORE3282: stdout: - Unhandled Exception thrown: class java.lang.NullPointerException
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: org.hibernate.hql.ast.QuerySyntaxException: DBO_FSOL.USERNAME is not mapped [select
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: UN.USERNAME_ID,UN.EMAIL_TX,UN.FIRST_NAME_TX,UN.LAST_NAME_TX,
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: UN.STATUS_CD,UN.DOB_DT,AD.ADDRESS1_TX,AD.ADDRESS2_TX,
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: AD.CITY_TX,AD.STATE_CD,AD.ZIP_CD
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: from
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: DBO_FSOL.USERNAME UN,
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: DBO_FSOL.ADDRESS AD
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: where UN.USERNAME_ID=AD.USERNAME_ID
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: and UN.USERNAME_ID=brian.beech]
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
[12/Jun/2007:15:46:49] warning ( 1113): CORE3283: stderr: at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromEl


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 4:33 pm 
Newbie

Joined: Wed May 30, 2007 4:14 pm
Posts: 15
All I really want to do is pass in an email address and retrieve that ojbect. If I pass in a hard coded ID value (primary key for the table) I get the object....now I just want it with an email address. Since this one object is spanned over two tables in the db, that's why I'm having trouble. ANY help would be nice. I'm a newbie and need some direction.

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 12, 2007 5:26 pm 
Newbie

Joined: Wed May 30, 2007 4:14 pm
Posts: 15
well, one thing is for sure, I was using the db names as opposed to the class/property names. But, That still hasn't fixed my problem.


Top
 Profile  
 
 Post subject: POST UPDATE
PostPosted: Tue Jun 12, 2007 6:54 pm 
Newbie

Joined: Wed May 30, 2007 4:14 pm
Posts: 15
no replies - :(

We'll scrap using hibernate because, I'm not sure where everyone else programs, but we have a very tight deadline.

NO need to reply


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 1:06 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
Are you specifying hibernate.cfg.xml in SessionFactory's configure method ? and using buildSessionFactory ?


Top
 Profile  
 
 Post subject: Re:
PostPosted: Wed Jun 13, 2007 1:58 am 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Try:

session.createSQLQuery(...);

instead of session.createQuery(...);


AND:

type caste the value returned by uniqueResult to Object[] will also be required.

Regards,
Jitendra


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 5:09 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Let me know if this solved your problem and kindly give appropriate credit.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 1:32 pm 
Newbie

Joined: Wed May 30, 2007 4:14 pm
Posts: 15
I'm sorry, but I'm not sure if this helped, if you read my posts above, we scrapped the use of hibernate in this project because we were on a tight deadline and had a hard time getting help with it. So, I wasn't ignoring you, I just don't know if your solution would have helped and that code no longer exists. thanks though.


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