-->
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: Unique index for many-to-many association(based on 2 fields)
PostPosted: Wed Aug 30, 2006 11:14 am 
Newbie

Joined: Fri Sep 23, 2005 6:25 am
Posts: 6
Hi,

I have the following class:

/**
* @hibernate.class table="movie"
*/
public class Movie extends BaseBusinessObject implements Serializable
{
/**
* @hibernate.property
* @hibernate.column name="name" not-null="true" length="30" unique="true"
*/
String name;

/**
* @hibernate.property
* @hibernate.column name="dateofissue" not-null="true"
*/
Date dateOfIssue;

/**
* @hibernate.property
* @hibernate.column name="length" not-null="true"
*/
Integer length;

/**
* @hibernate.many-to-many class="com.acasa.annotation.pojo.Actor" column="actor_id" foreign-key="FK_ACTOR"
* @hibernate.key column="movie_id" foreign-key="FK_MOVIE"
* @hibernate.list table="movie_details" lazy="true" inverse="true"
* @hibernate.list-index column="idx"
*/
java.util.List<Actor> distribution;

/**
* @hibernate.many-to-one
* class="com.acasa.annotation.pojo.Producer"
* foreign-key="FK_PRODUCER"
*/
Producer producer;
}

XDoclet2 will generate the following mapping file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class table="movie" name="com.acasa.annotation.pojo.Movie">
<id access="field" name="id">
<generator class="sequence"/>
</id>
<version column="version" unsaved-value="undefined" access="field" name="version"/>
<property name="name" access="field">
<column name="name" not-null="true" length="30" unique="true"/>
</property>
<property name="dateOfIssue" access="field">
<column name="dateofissue" not-null="true"/>
</property>
<property name="length" access="field">
<column name="length" not-null="true"/>
</property>
<list table="movie_details" access="field" lazy="true" inverse="true" name="distribution">
<key foreign-key="FK_MOVIE" column="movie_id"/>
<list-index column="idx"/>
<many-to-many foreign-key="FK_ACTOR" column="actor_id" class="com.acasa.annotation.pojo.Actor"/>
</list>
<many-to-one foreign-key="FK_PRODUCER" access="field" name="producer" class="com.acasa.annotation.pojo.Producer"/>
</class>
</hibernate-mapping>


Hibernate will create these 2 tables:

create table movie (id int4 not null, version int4 not null, name varchar(30) not null unique, dateofissue timestamp not null, length int4 not null, producer int4, primary key (id));
create table movie_details (movie_id int4 not null, actor_id int4 not null, idx int4 not null);

What hibernate tags should I use in order to create an unique constraint on columns "movie_id" and "actor_id" for table "movie_details"?

Thanks,
Vasile


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.