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