-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to join interconnecting tables
PostPosted: Thu Jul 13, 2006 11:03 am 
Beginner
Beginner

Joined: Thu Jul 13, 2006 10:39 am
Posts: 23
I am very new to Hibernate.

I have to join more than two tables. I can give my table structure. My table structure is as follows:

Table structure

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


I don't know how to create hbm file for this class.

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 1:00 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Code:
<class name="Submission" ...>
  ...
  <set name="sessions" inverse="false" cascade="all-delete-orphan" ...>
    <key column="submission_id"/>
    <one-to-many class="ValSession"/>
  </set>
  ...
</class>
<class name="ValSession" ...>
  ...
  <set name="stati" 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="Submission" .../>
  ...
</class>
<class name="ValStatus" ...>
  ...
  <many-to-one name="Session" insert="false" update="false" class="ValSession" .../>
  ...
</class>

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: How to Interconnect tables inhibernate
PostPosted: Fri Jul 14, 2006 1:16 am 
Beginner
Beginner

Joined: Thu Jul 13, 2006 10:39 am
Posts: 23
Thank you for reply...

tenwit wrote:
Code:
<class name="Submission" ...>
  ...
  <set name="sessions" inverse="false" cascade="all-delete-orphan" ...>
    <key column="submission_id"/>
    <one-to-many class="ValSession"/>
  </set>
  ...
</class>
<class name="ValSession" ...>
  ...
  <set name="stati" 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="Submission" .../>
  ...
</class>
<class name="ValStatus" ...>
  ...
  <many-to-one name="Session" insert="false" update="false" class="ValSession" .../>
  ...
</class>


Top
 Profile  
 
 Post subject: How to join interconnecting tables
PostPosted: Fri Jul 14, 2006 2:56 am 
Beginner
Beginner

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

Thanks for the reply.

I created hbm file as you mail me. But 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 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 you please help me to tackle this issue.


Thanks and Regards,
Sreekanth
















tenwit wrote:
Code:
<class name="Submission" ...>
  ...
  <set name="sessions" inverse="false" cascade="all-delete-orphan" ...>
    <key column="submission_id"/>
    <one-to-many class="ValSession"/>
  </set>
  ...
</class>
<class name="ValSession" ...>
  ...
  <set name="stati" 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="Submission" .../>
  ...
</class>
<class name="ValStatus" ...>
  ...
  <many-to-one name="Session" insert="false" update="false" class="ValSession" .../>
  ...
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 16, 2006 5:47 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Sure. Is Submissions.getSubmissionId() returning a String? And there's a method Submissions.setSubmissionId(String x)? The error is saying that there's a type mismatch between your mapping file and your java file.

_________________
Code tags are your friend. Know them and use them.


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