-->
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.  [ 1 post ] 
Author Message
 Post subject: How to make one-to-one mapping?
PostPosted: Mon Nov 12, 2007 9:16 pm 
Newbie

Joined: Fri Jun 08, 2007 3:16 am
Posts: 11
I have two table,user table and book card table,like follows:
User table:
Code:
user_id varchar2(20);
user_name varchar2(20);


Book card table:
Code:
card_id varchar2(20);
user_id varchar2(20);


TableNode.java
Code:
Public class TableNode{
   String user_id;
   String user_name;
   //set and get method
   //...
}


BookCardNode.java
Code:
Public class BookCardNode{
   String card_id;
   String user_id;
   //set and get method
   //...
}


Then I make table mapping under Hibernate
User.hrb.xml
Code:
<hibernate-mapping>
  <class name="UserNode" table="USER">
    <property name="user_id" type="java.lang.String">
      <column name="user_id" length="20" not-null="true" />
    </property>
    <property name="user_name" type="java.lang.String">
      <column name="user_name" length="20" not-null="true" />
    </property>
  </class>
</hibernate-mapping>


BookCard.hrb.xml
Code:
<hibernate-mapping>
  <class name="BookCardNode" table="BOOKCARD">
    <property name="card_id" type="java.lang.String">
      <column name="card_id" length="20" not-null="true" />
    </property>
    <property name="user_id" type="java.lang.String">
      <column name="user_id" length="20" not-null="true" />
    </property>
  </class>
</hibernate-mapping>


I have two question:
Question 1: I want to make User.hrb.xml and BookCard.hrb.xml with one-to-one relationship,but I don’t know how to modify above User.hrb.xml and BookCard.hrb.xml?

Question 2:I have following data,
User table
Code:
User_id  user_name
John    SmithPeter
Kate    Kate J.


Book Card table
Code:
Card_id  user_id
1002   John


Then I query book card table,like following:
Code:
List info=this.getHibernateTemplate().find("from BookCardNode where and user_id=’John’)


I want to this result List contains such data: 1002 John SmithPeter

My question is how to write this.getHibernateTemplate().find(“?????"),and how to extract data from List?

Please give me detail statement,Thanks in advance!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.