[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2273) AnnotationConfiguration generateSchemaCreationScript OneToMany constraints problem
Milan Pecko (JIRA)
noreply at atlassian.com
Thu Nov 30 11:42:04 EST 2006
AnnotationConfiguration generateSchemaCreationScript OneToMany constraints problem
----------------------------------------------------------------------------------
Key: HHH-2273
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2273
Project: Hibernate3
Type: Bug
Versions: 3.2.0.ga
Environment: Windows XP,
Sun java 1.5.0-06
MSSQL
Reporter: Milan Pecko
There is a base class TBase. T1 and T2 extends from TBase (InheritanceType.JOINED) (and many others too),
T1 and T2 has a collection references to TRef, TRef references TBase,
see below for short class definition.
schema creation produces constraints :
alter table T_REF_TBL add constraint con_1_ foreign key (refId) references T_BASE_TBL
alter table T_REF_TBL add constraint con_2_ foreign key (refId) references T_1_TBL
alter table T_REF_TBL add constraint con_2_ foreign key (refId) references T_2_TBL
so there is no posibility to store T1 or T2 due constraint violation exception.
I have tried to use middleclass TBaseWithSet (annotated as @MappedSuperclass) with collection but the same constraints was created.
Shor class definition:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "T_BASE_TBL")
public class TBase implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
...
}
........
}
@Entity
@javax.persistence.Table(name = "T_REF_TBL")
@ExcomWeb(urn = "Excom2:InstrumentInterestRateEntry")
public class TRef implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
...
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "refId")
public TBase getBase() {
....;
}
........
}
@Entity
@PrimaryKeyJoinColumn(name = "id")
@Table(name = "T1_TBL")
public class T1 extends TBase implements java.io.Serializable {
@OneToMany(targetEntity = TRef.class, mappedBy = "refId" fetch = FetchType.LAZY)
@Cascade( {org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN} )
public Set getReferencies() {
...
}
...........
}
@Entity
@PrimaryKeyJoinColumn(name = "id")
@Table(name = "T2_TBL")
public class T2 extends TBase implements java.io.Serializable {
@OneToMany(targetEntity = TRef.class, mappedBy = "refId" fetch = FetchType.LAZY)
@Cascade( {org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN} )
public Set getReferencies() {
...
}
...........
}
schema export :
...
alter table T_REF_TBL add constraint con_1_ foreign key (refId) references T_BASE_TBL
alter table T_REF_TBL add constraint con_2_ foreign key (refId) references T_1_TBL
alter table T_REF_TBL add constraint con_2_ foreign key (refId) references T_2_TBL
...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list