-->
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: mapping pojo property:no relation between db tables [SOLVED]
PostPosted: Thu Feb 26, 2009 3:17 pm 
Newbie

Joined: Thu Feb 26, 2009 2:22 pm
Posts: 9
Hi, I have two pojo i.e.

class A
{
int a_id;
String name;
Timestamp a_time;
}

class B
{
int b_id;
int x;
Timestamp b_time;
A a; <<<<<<<<<<<<<<<<< how to initialize 'a' through mapping?
}

When I get from db pojo 'B' I want to initialize (through mapping) property 'A' in pojo 'B' by special sql query (i.e. from A as a when a.a_time = b.b_time), but there is no relation between database tables (PK, FK). Is it possiable?


Last edited by entaroadun7 on Mon Mar 02, 2009 6:25 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2009 1:37 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
You can map the relation like this.

Code:
   <class name="A">
      <id name="a_id" column="A_ID" type="int" unsaved-value="0">
         <generator class="native" />
      </id>
      
      <property name="name" />
      
      <property name="a_time" column="A_TIME" unique="true"/>
   </class>

   <class name="B">
      <id name="b_id" column="B_ID" type="int" unsaved-value="0">
         <generator class="native" />
      </id>
      
      <property name="x" />
      
      <many-to-one name="a" class="A" property-ref="a_time" column="B_TIME" fetch="join"></many-to-one>
   </class>


Please note <property name="a_time" unique="true"/>
The referring property should be unique as this is a many-to-one relation. Your B has only one related A.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2009 5:05 am 
Newbie

Joined: Thu Feb 26, 2009 2:22 pm
Posts: 9
Thanks for replay. But is it possible to do this with query ? In case of one property needs value(s) from 3rd table i.e. from A as a when a.a_time = b.b_time and a.name = (select c.name form C where c.x = b.x) ?
ps. 'a' unique when a.a_time = b.b_time and a.name = (select c.name form C where c.x = b.x). Thx


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 1:38 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
I think you can use formula to map such queries to properties. Didnt use it, but u can try searchng for tht.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject: mapping pojo property (no relation between database tables)
PostPosted: Mon Mar 02, 2009 6:23 pm 
Newbie

Joined: Thu Feb 26, 2009 2:22 pm
Posts: 9
Thanks, 'formula' solved the problem.


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.