CollectionOfElements annotations seems to generate an incorrect foreign key constraint with hbm2ddl.
Hibernate version:
3.2.5.ga
Mapping documents:
public class SpaceObject extends BaseObject implements Serializable,
SpaceObjectI {
...
@CollectionOfElements(targetElement=Integer.class)
@JoinTable(
name="spaceObject_tag",
joinColumns = @JoinColumn(name="space_object")
)
@Column(name="uses", nullable=false)
@MapKeyManyToMany(targetEntity = Tag.class, joinColumns = @JoinColumn(name="tag_id"))
public Map<TagI, Integer> getTags() {
if (tags == null)
tags = new HashMap<TagI, Integer>();
return tags;
}
}
The generated SQL (show_sql=true):
Here's what
sweeti_test=> \d tbl_space_object__tag
Table "public.tbl_space_object__tag"
Column | Type | Modifiers
---------------+---------+-----------
space__object | bigint | not null
uses | integer | not null
tag__id | bigint | not null
Indexes:
"tbl_space_object__tag_pkey" PRIMARY KEY, btree (space__object, tag__id)
Foreign-key constraints:
"fk10c39fe12f27b5ad" FOREIGN KEY (tag__id) REFERENCES tbl_space_object(id) D
EFERRABLE
"fk10c39fe18bad9de4" FOREIGN KEY (uses) REFERENCES tbl_space_object(id) DEFE
RRABLE
"fk10c39fe1dfcf8a88" FOREIGN KEY (space__object) REFERENCES tbl_space_object
(id) DEFERRABLE
|