-->
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.  [ 4 posts ] 
Author Message
 Post subject: hql join query
PostPosted: Thu Dec 18, 2008 6:18 am 
Newbie

Joined: Thu Dec 18, 2008 6:10 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:
Document.hbm.xml
<class name="com.servient.discovery.model.document.DocumentStampSearch" table="document" schema="public">
<composite-id name="id" class="com.servient.discovery.model.document.DocumentId">
<key-property name="subscriberId" type="integer">
<column name="subscriber_id" />
</key-property>
<key-property name="caseId" type="integer">
<column name="case_id" />
</key-property>
<key-property name="documentId" type="double">
<column name="document_id" precision="12" scale="3" />
</key-property>
</composite-id>
<property name="subscriberId" column="subscriber_id" type="integer" not-null="true" insert="false" update="false"/>
<property name="caseId" column="case_id" type="integer" not-null="true" insert="false" update="false"/>
<property name="documentId" column="document_id" type="integer" not-null="true" insert="false" update="false"/>
<property name="documentType" column="document_type" type="string" length="15" not-null="true" />
<property name="subscriber" column="subscriber" type="string" length="50" not-null="true" />

<set name="stamps" inverse="true">
<key>
<column name="subscriber_id" not-null="true" />
<column name="case_id" not-null="true" />
<column name="document_id" precision="12" scale="3" not-null="true" />
</key>
<one-to-many class="com.servient.discovery.model.stamp.StampDocumentSearch" />
</set>
</class>

Stamp.hbm.xml -
<class name="com.servient.discovery.model.stamp.StampDocumentSearch" table="stamp" schema="public">
<composite-id name="id" class="com.servient.discovery.model.stamp.StampId">
<key-property name="subscriberId" type="integer">
<column name="subscriber_id" />
</key-property>
<key-property name="caseId" type="integer">
<column name="case_id" />
</key-property>
<key-property name="documentId" type="double">
<column name="document_id" precision="12" scale="3" />
</key-property>
</composite-id>
<many-to-one name="document" class="com.servient.discovery.model.document.DocumentStampSearch" update="false" insert="false" fetch="select">
<column name="subscriber_id" not-null="true" />
<column name="case_id" not-null="true" />
<column name="document_id" precision="12" scale="3" not-null="true" />
</many-to-one>
<property name="batesSuffix" type="string">
<column name="bates_suffix" length="32" />
</property>
<property name="batesPrefix" type="string">
<column name="bates_prefix" length="32" not-null="true" />
</property>
<property name="beginningBates" type="long">
<column name="beginning_bates" length="32" not-null="true" />
</property>
</class>

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


Full stack trace of any exception that occurs:

java.lang.NullPointerException
at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:264)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3022)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2841)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2719)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:513)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.servient.discovery.dataservice.DocumentDataService.query(DocumentDataService.java:116)
at com.servient.discovery.dataservice.DocumentDataService.main(DocumentDataService.java:323)


Name and version of the database you are using:
postgres 8.3

The generated SQL (show_sql=true):


Debug level Hibernate log excerpt:


I have respective POJOs to represent both classes. I need to join these two objects to retrieve the fields from DocumentStampSearch and StampDocumentSearch. The hql query designed by me is as follows -

from DocumentStampSearch as doc left outer join com.servient.discovery.model.stamp.StampDocumentSearch as stamp where doc.subscriberId= :subscriberId and doc.caseId = :caseId

and in addition to this i need to apply one more criteria i.e. documentId field in StampDocumentSearch should not be null and i want to fetch all those records.

Can anyone help me in building this hql query?

Environment used -
jboss - 4.2 GA
Hibernate - 3.0

Thanks,
Vrushali


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 7:52 am 
Newbie

Joined: Mon Oct 01, 2007 8:59 am
Posts: 18
Plz send me the complete code let me check it ganga.tanwar@gmail.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 8:16 am 
Newbie

Joined: Mon Oct 01, 2007 8:59 am
Posts: 18
Plz send me the complete code let me check it ganga.tanwar@gmail.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 10:15 am 
Newbie

Joined: Thu Dec 18, 2008 6:10 am
Posts: 2
Thanks for your immidiate reply. I solved the problem.

The query fired is - "from DocumentStampSubsetSearch as document
left join fetch document.stamps
where document.subscriberId= :subscriberId and
document.caseId= :caseId"

Query change served my purpose and it got executed.

Thanks once again


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