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