-->
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: many to many and adding extra info in mapping table
PostPosted: Mon Jul 02, 2007 7:05 am 
Newbie

Joined: Mon Jul 02, 2007 6:46 am
Posts: 1
Location: India
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.2

Mapping documents:
<hibernate-mapping>

<class name="hib.association.many_to_many.unidirectional.model.UserModel" table="many_to_many_user">
<id name="userId" column="user_Id" type="long">
<generator class="increment"/>
</id>
<property name="firstName"
column="first_name"
type="string"/>
<property name="lastName"
column="last_name"
type="string"/>
<property name="userName"
column="user_name"
unique="true"
not-null="true"
type="string"/>
<property name="password"
column="password"
type="string"/>
<!--
in many_to_many_user_address_mapping both user_id and addressId creates composite key
-->
<set name="addresses"
table="many_to_many_user_address_mapping">
<key column="user_id"/>
<many-to-many column="addressId"
class="hib.association.many_to_many.unidirectional.model.AddressModel"/>
</set>

</class>

<class name="hib.association.many_to_many.unidirectional.model.AddressModel" table="many_to_many_address">
<id name="addressId" column="address_Id" type="long">
<generator class="increment"/>
</id>
<property name="street"
column="street"
type="string"/>
<property name="state"
column="state"
type="string"/>
<property name="city"
column="city"
type="string"/>
<property name="country"
column="country"
type="string"/>
</class>



database create table query

for user table
CREATE TABLE many_to_many_user (
user_Id bigint(20) NOT NULL,
first_name varchar(255) default NULL,
last_name varchar(255) default NULL,
user_name varchar(255) NOT NULL,
password varchar(255) default NULL,
PRIMARY KEY (user_Id)
)

for address table
CREATE TABLE many_to_many_address (
address_Id bigint(20) NOT NULL,
street varchar(255) default NULL,
state varchar(255) default NULL,
city varchar(255) default NULL,
country varchar(255) default NULL,
PRIMARY KEY (address_Id)
)

for mapping table
CREATE TABLE many_to_many_user_address_mapping (
user_id bigint(20) NOT NULL,
addressId bigint(20) NOT NULL,
add_date timestamp,
edit_date timestamp,

PRIMARY KEY (user_id,addressId),
)

i do'nt know how to insert information in add_date and edit_ date


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.