-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to use Criteria in Hibernate
PostPosted: Fri Jul 14, 2006 3:07 am 
Beginner
Beginner

Joined: Thu Jul 13, 2006 10:39 am
Posts: 23
Hi,

I have a problem while using criteria in Hibernate.

The problem I found is when I select max(last_modified_ts) of a particular val_status_id whose submission_id='' and val_def_mod_res_id=''. It is showing error.

My table structure look like this:
---------------------------


val_status :
------------------
val_status_id raw primary key
val_session_id raw foreign key
created_ts date
last_modified_ts date
val_def_mod_res_id raw

val_session:
---------------------------
val_session_id raw primary key
submission_id raw foriegn key
created_ts date
last_modified_ts date

Submission:
--------------------------------
submission_id raw primary key
submission_no
submission_name
creted_ts date
last_modified_ts date
-------------------------------------------------------------------

My hbm file look like this
-----------------------------------------------------------------------------------
<class name="ValStatus" table="val_status">
<id name="valStatusId" type="string" unsaved-value="null" >
<column name="val_status_id" sql-type="raw(16)" not-null="true"/>
</id>
..................

<property name="valDefModResId" >
<column name="val_def_mod_res_id" sql-type="raw(16)" not-
null="true"/>
</property>

<many-to-one name="Stage" insert="false" update="false"
class="ValStages" column="val_stage_id"/>

<many-to-one name="Session" insert="false" update="false"
class="ValSession" column="val_session_id"/>


</class>

<class name="ValSession" table="val_session">
<id name="valSessionId" type="string" unsaved-value="null" >
<column name="val_session_id" sql-type="raw(16)" not-null="true"/>
</id>
................................
<set name="status" inverse="false" cascade="all-delete-orphan">
<key column="val_session_id"/>
<one-to-many class="ValStatus"/>
</set>

<many-to-one name="Submission" insert="false" update="false"
class="Submissions" column="submission_id" />

</class>

<class name="Submissions" table="submission">

<id name="submissionId" type="string" unsaved-value="null" >
<column name="submission_id" sql-type="raw(16)" not-null="true"/>
</id>
---------------
</class>

---------------------------------------------------------------------------

I didn't create property for submission_id in ValSession.hbm file and val_session__id in valStatus.hbm file.

My sample code look like this:

SessionFactory sessionFactory=HibernateFactory.buildsessionFactory();
Session session= sessionFactory.openSession();

Criteria critLastModDate = session.createCriteria(ValStatus.class)
.setProjection(Projections.max("lastModifiedTs"))
.add(Restrictions.eq
("valDefModResId","CBD54AB05DBA4769944023B15D0ABEC9"));

Criteria prdCrit = critLastModDate.createCriteria("Session");
prdCrit.add(Restrictions.eq("Submission","831405D303064887B1AF63F55D3C3690"));

List results = critLastModDate.list();
System.out.println(results.get(0));


Error shows like this:

Hibernate: select max(this_.last_modified_ts) as y0_ from val_status this_, val_session valsession1_ where this_.val_session_id=valsession1_.val_session_id and this_.val_def_mod_res_id=? and valsession1_.submission_id=?
- IllegalArgumentException in class: hibernate.Submissions, getter method of property: submissionId

Could anyone please to solve this problem

Please do favour with me.

Thanks and Regards,
Sreekanth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 3:55 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Try

Code:
prdCrit.add(Restrictions.eq("Submission.submissionId","831405D303064887B1AF63F55D3C3690"));


Top
 Profile  
 
 Post subject: how to use Criteria in Hibernate.
PostPosted: Fri Jul 14, 2006 4:48 am 
Beginner
Beginner

Joined: Thu Jul 13, 2006 10:39 am
Posts: 23
Thanks for ur reply...

It is working fine....Thanks a lot

Have a nice day,

Thanks and regards,
Sreekanth



JayeshJ wrote:
Try

Code:
prdCrit.add(Restrictions.eq("Submission.submissionId","831405D303064887B1AF63F55D3C3690"));


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