-->
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: Simple column mapping.
PostPosted: Wed Mar 31, 2010 5:25 am 
Newbie

Joined: Thu Mar 25, 2010 5:14 am
Posts: 8
I have a class structure similar to something like
Code:
class A
{
  B b;
  int id;
  int bid;
  int x;
};

class B
{
int bid;
int id;
A x;
String s;
}


Now if I wish to have a mapping in such a way that variable X (a common column in both tables ) that is set in class A is propogated to class B.

Can anyone help me out?

I am trying out hibernate and using many-to-one as association but it is not working.


Top
 Profile  
 
 Post subject: Re: Simple column mapping.
PostPosted: Wed Mar 31, 2010 5:26 am 
Newbie

Joined: Thu Mar 25, 2010 5:14 am
Posts: 8
I have used the object X in class B as object to class A for simplified association in hibernate.


Top
 Profile  
 
 Post subject: Re: Simple column mapping.
PostPosted: Wed Mar 31, 2010 5:59 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Could you pls post the code and mapping...


Top
 Profile  
 
 Post subject: Re: Simple column mapping.
PostPosted: Wed Mar 31, 2010 6:25 am 
Newbie

Joined: Thu Mar 25, 2010 5:14 am
Posts: 8
For class A
Code:
<class name="A" table="TABLE1">
 
     <id name="id" type="long" column="ID">
            <generator class="increment" />
     </id>
     
     <property name="x" type="long" column="UNIT" />   
     
     <many-to-one name="b" class="B" cascade="all" outer-join="true">
            <column name="BID" not-null="true"/>
     </many-to-one>               
  </class>


For B

Code:
<class name="B" table="TABLE2">
 
     <id name="bid" type="long" column="BID">
            <generator class="increment" />
     </id>
     
     <property name="s" type="string" column="DENOM" />   
     <property name="id" type="long" column="VALUE" />   
     
     <many-to-one name="x" class="A">
            <column name="UNIT" />
     </many-to-one>               

  </class>



Table looks like
TABLE1
ID <- Autogenerated
UNIT <- value to propogate
BID <- Value from table 2

TABLE2
BID <- Autogenerated
UNIT <- value to fetch from table 1
VALUE
DENOM


I am saving object of class A that introduces new row for table 2


Top
 Profile  
 
 Post subject: Re: Simple column mapping.
PostPosted: Wed Mar 31, 2010 6:52 am 
Newbie

Joined: Thu Mar 25, 2010 5:14 am
Posts: 8
Well i was wondering what is the rigth approach of developing in hibernate, first define a POJO and then work on database structures or may be the reverse?

Considering, if the POJO uses composition

Like in question above, Class A contains Class B, and there are common values that are used to form referential integrity to constitute a common value set it is not easy to define value associations is it?

(May be it is a stupid questions, do excuse me, I am just learning it)


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.