-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate newbie needs help with association mapping
PostPosted: Sun Mar 16, 2008 4:23 pm 
Newbie

Joined: Sun Mar 16, 2008 3:59 pm
Posts: 1
Hi!

I have 2 sample DB tables:

1) employee (id, name, address); id is a primary key
2) salary(emp_id, salary); emp_id column is a foreign key to employee(id)

I have one persistent class Employee:
Code:
package data;
public class Employee {
   private int id;
   private String name, address;
   private double salary; // references a column in Salary table
................... setters/getters ...........
}


How can I modify the below association mapping so that when I insert 1 record into the the Employee object/table, 1 row is also inserted into the Salary table automatically?
Code:
<class name="data.Employee" table="employee">
  <id name="id" column="id" type="java.lang.Integer">
    <generator class="native" />
  </id>
      
  <property name="name" column="name" type="java.lang.String" />
  <property name="address" column="address" type="java.lang.String" />
</class>


Many thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 7:47 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
Take a look at @SecondaryTable in the annotations reference, I am sure there's a similar configuration option in hibernate classic.

_________________
http://www.ohloh.net/accounts/ge0ffrey


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.