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
|