Hibernate version: 3.2.6.ga
Name and version of the database you are using: Oracle 10.2.0.3.0
Hi,
I have 3 annotated entity classes: FieldWidget, GridWidget and GridFieldWidget.
FieldWidget has the fields: id and uid.
GridWidget has the fields: id, name and a collection of GridFieldWidget.
GridFieldWidget has the fields: id, grid (ref to GridWidget), field (ref to FieldWidget) and show.
I use hbm2ddl to generate their sqls.
I have a question about one generated sql.
This is the sql:
Code:
alter table eval_x_grdwdg_fldwdg
add constraint FK7EDC7B30718ADE14
foreign key (xgrdwdgfldwdg_fldwdg_id)
references eval_x_grdwdg_fldwdg;
I known that this sql is generated with this annotation:
Code:
@ManyToMany
@JoinTable(name = "eval_x_grdwdg_fldwdg",
joinColumns = @JoinColumn(name = "xgrdwdgfldwdg_grdwdg_id"),
inverseJoinColumns = @JoinColumn(name = "xgrdwdgfldwdg_fldwdg_id")
)
private Collection<GridFieldWidget> fields;
But actually this generated sql should be something like (I think):
Code:
alter table eval_x_grdwdg_fldwdg
add constraint FK7EDC7B30F2EA5D3A
foreign key (xgrdwdgfldwdg_fldwdg_id)
references eval_field_widgets;
Any ideas what I'm doing wrong ?
How can I solved/fix this ?
See below for a more in detail summary of the 3 annotated classes and their generated sqls.
Thanks in advance.
Tim
The
FieldWidget entity class:
Code:
@Entity
@Table(name = "eval_field_widgets")
public class FieldWidget{
@Id
@Column(name = "fldwdg_id")
private Long id;
@Column(name = "fldwdg_uid", unique = true, nullable = false, length = 40)
private String uid;
}
This gives the following sql generated with the hbm2ddl tool:
Code:
create table eval_field_widgets(
fldwdg_id number(19,0) not null,
fldwdg_uid varchar2(40 char) not null unique,
primary key (fldwdg_id)
);
The
GridWidget entity class:
Code:
@Entity
@Table(name = "eval_grid_widgets")
public class GridWidget{
@Id
@Column(name = "grdwdg_id")
private Long id;
@Column(name = "grdwdg_desc", nullable = false, length = 240)
private String name;
@ManyToMany
@JoinTable(name = "eval_x_grdwdg_fldwdg",
joinColumns = @JoinColumn(name = "xgrdwdgfldwdg_grdwdg_id"),
inverseJoinColumns = @JoinColumn(name = "xgrdwdgfldwdg_fldwdg_id")
)
private Collection<GridFieldWidget> fields;
}
This gives the following sql generated with the hbm2ddl tool:
Code:
create table eval_grid_widgets(
grdwdg_id number(19,0) not null,
grdwdg_desc varchar2(240 char) not null,
primary key (grdwdg_id)
);
The
GridFieldWidget entity class:
Code:
@Entity
@Table(name = "eval_x_grdwdg_fldwdg", uniqueConstraints = @UniqueConstraint(columnNames = {"xgrdwdgfldwdg_grdwdg_id", "xgrdwdgfldwdg_fldwdg_id"}))
public class GridFieldWidget{
@Id
@Column(name = "xgrdwdgfldwdg_id")
private Long id;
@OneToOne
@JoinColumn(name = "xgrdwdgfldwdg_grdwdg_id", nullable = false)
private GridWidget grid;
@OneToOne
@JoinColumn(name = "xgrdwdgfldwdg_fldwdg_id", nullable = false)
private FieldWidget field;
@Column(name = "xgrdwdgfldwdg_show", nullable = false)
private boolean show;
}
This gives the following sql generated with the hbm2ddl tool:
Code:
create table eval_x_grdwdg_fldwdg(
xgrdwdgfldwdg_id number(19,0) not null,
xgrdwdgfldwdg_grdwdg_id number(19,0) not null,
xgrdwdgfldwdg_fldwdg_id number(19,0) not null,
xgrdwdgfldwdg_show number(1,0) not null,
primary key (xgrdwdgfldwdg_id),
unique (xgrdwdgfldwdg_grdwdg_id, xgrdwdgfldwdg_fldwdg_id)
);
alter table eval_x_grdwdg_fldwdg
add constraint FK7EDC7B30718ADE14
foreign key (xgrdwdgfldwdg_fldwdg_id)
references eval_x_grdwdg_fldwdg;
alter table eval_x_grdwdg_fldwdg
add constraint FK7EDC7B30F2EA5D3A
foreign key (xgrdwdgfldwdg_fldwdg_id)
references eval_field_widgets;
alter table eval_x_grdwdg_fldwdg
add constraint FK7EDC7B309430EAF1
foreign key (xgrdwdgfldwdg_grdwdg_id)
references eval_grid_widgets;