-->
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.  [ 4 posts ] 
Author Message
 Post subject: composite unique key
PostPosted: Tue Aug 02, 2005 6:05 am 
Beginner
Beginner

Joined: Wed Jun 08, 2005 10:01 am
Posts: 22
Location: Italy
Hi !
I am experimenting annotations
and writing a class which describe the following table:

Quote:
CREATE TABLE admissible_values
(
admissible_value_id bigserial NOT NULL,
attribute_id int8 NOT NULL,
class_id int8 NOT NULL,
start_value varchar(50) NOT NULL,
end_value varchar(50) NOT NULL,
default_value varchar(50),
status int4 NOT NULL DEFAULT 0,
CONSTRAINT admissible_pkey PRIMARY KEY (admissible_value_id),
CONSTRAINT admissible_classid_attributeid_key UNIQUE (class_id, attribute_id)
)


How can I annotate the composite UNIQUE KEY
(class_id, attribute_id) which is composed by 2 foreign key ?
Quote:
/**

* AdmissibleValues generated by hbm2java

*/

@Entity

@Table(name = "admissible_values", schema = "public")

public class AdmissibleValues implements java.io.Serializable {

// Fields

private java.lang.Long AdmissibleValueId;

private com.aaa.entity.Classes Classes;

private com.aaa.entity.Attributes Attributes;

[...cut]

@ManyToOne
@JoinColumn(name = "class_id")
public com.aaa.entity.Classes getClasses () {
return this.Classes;
}

public void setClasses (com.aaa.entity.Classes Classes) {
this.Classes = Classes;
}

@ManyToOne
@JoinColumn(name = "attribute_id")
public com.aaa.entity.Attributes getAttributes () {
return this.Attributes;
}

public void setAttributes (com.aaa.entity.Attributes Attributes) {
this.Attributes = Attributes;
}



I cannot use UNIQUE parameter into @JoinColumn
in Classes and Attributes.

How can I solve this ?

Thank in advance,
Nicola


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 2:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
@Table(uniqueconstraints = ...)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 7:53 am 
Beginner
Beginner

Joined: Wed Jun 08, 2005 10:01 am
Posts: 22
Location: Italy
Thank you emmanuel.

I post the code as solution example.

Quote:
@Entity
@Table(uniqueConstraints = {@UniqueConstraint(columnNames={"class_id",
"attribute_id"})}, name = "admissible_values", schema = "public")

public class AdmissibleValues implements java.io.Serializable {

... [class implementation]

}



bye


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 5:27 pm 
Newbie

Joined: Tue Dec 28, 2004 12:12 am
Posts: 5
Hi I want to do something very similar to what you did. But I am using
xdoclet to generate the various hibernate configuration files. I can't
seem to find the corresponding xdoclet tags. Have I simply not found them,
does xdoclet not support this feature, or I am missing something altogether.

Thanks,
Hani


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