Hi
I'm restricted to use JDK 1.4, therefore i can not use annotations, also we have expectations of use all HB-Tools generated files (HBM, POJOs and DAOs) and only uses reverse engineering controllers for fix problems in the generated code. (the reveng file in this case).
The follow SQL code reproduces the error (MS SQL Server 2000 SP3):
Code:
CREATE TABLE dbo.ITEM (
id_item int NOT NULL,
name_item varchar(32)
)
go
ALTER TABLE dbo.ITEM ADD PRIMARY KEY CLUSTERED (id_item ASC)
go
CREATE TABLE dbo.UNIT_GROUP (
id_UNIT_GROUP int NOT NULL,
name_UNIT_GROUP varchar(32)
)
go
ALTER TABLE dbo.UNIT_GROUP ADD PRIMARY KEY CLUSTERED (id_UNIT_GROUP ASC)
go
CREATE TABLE dbo.UNIT_GROUP_ITEM (
id_UNIT_GROUP int NOT NULL,
id_item int NOT NULL,
effective datetime NOT NULL,
price decimal(8,3) NOT NULL,
)
go
ALTER TABLE dbo.UNIT_GROUP_ITEM
ADD PRIMARY KEY CLUSTERED (id_UNIT_GROUP ASC, id_item ASC)
go
CREATE TABLE dbo.PS_IDENTITY (
id_UNIT_GROUP int NOT NULL,
id_item_ps varchar(14) NOT NULL,
id_item int NOT NULL,
effective datetime,
)
go
ALTER TABLE dbo.PS_IDENTITY
ADD PRIMARY KEY CLUSTERED (id_UNIT_GROUP ASC, id_item_ps ASC)
go
ALTER TABLE dbo.UNIT_GROUP_ITEM
ADD FOREIGN KEY (id_UNIT_GROUP) REFERENCES dbo.UNIT_GROUP (id_UNIT_GROUP)
go
ALTER TABLE dbo.UNIT_GROUP_ITEM
ADD FOREIGN KEY (id_item) REFERENCES dbo.ITEM (id_item)
go
ALTER TABLE dbo.PS_IDENTITY
ADD FOREIGN KEY (id_UNIT_GROUP) REFERENCES dbo.UNIT_GROUP (id_UNIT_GROUP)
go
ALTER TABLE dbo.PS_IDENTITY
ADD FOREIGN KEY (id_UNIT_GROUP, id_item)
REFERENCES dbo.UNIT_GROUP_ITEM (id_UNIT_GROUP, id_item)
go
The reverse engineering process generated POJOs and DAO (Home) classes. With this classes I try to persist an object in PS_Identity:
Code:
...
UnitGroup group = lookupUnitGroup (new Integer (0));
Item item = lookupItem (new Integer (0));
UnitGroupItem group_item = lookupUnitGroupItem (group, item);
PsIdentityId identity_id = new PsIdentityId (group.getIdUnitGroup(), "12345");
PsIdentity identity = new PsIdentity (identity_id, group, group_item);
PsIdentityHome identity_dao = new PsIdentityHome ();
identity_dao.persist(identity);
hb_tran.commit();
and this is the output:
Code:
...
Hibernate: select unitgroup0_.id_UNIT_GROUP as id1_0_0_, unitgroup0_.name_UNIT_GROUP as name2_0_0_ from bopos.dbo.UNIT_GROUP unitgroup0_ where unitgroup0_.id_UNIT_GROUP=?
Hibernate: select item0_.id_item as id1_2_0_, item0_.name_item as name2_2_0_ from bopos.dbo.ITEM item0_ where item0_.id_item=?
Hibernate: select unitgroupi0_.id_UNIT_GROUP as id1_1_0_, unitgroupi0_.id_item as id2_1_0_, unitgroupi0_.effective as effective1_0_, unitgroupi0_.price as price1_0_ from bopos.dbo.UNIT_GROUP_ITEM unitgroupi0_ where unitgroupi0_.id_UNIT_GROUP=? and unitgroupi0_.id_item=?
Hibernate: insert into bopos.dbo.UNIT_GROUP (name_UNIT_GROUP, id_UNIT_GROUP) values (?, ?)
Hibernate: insert into bopos.dbo.ITEM (name_item, id_item) values (?, ?)
Hibernate: insert into bopos.dbo.UNIT_GROUP_ITEM (effective, price, id_UNIT_GROUP, id_item) values (?, ?, ?, ?)
Hibernate: insert into bopos.dbo.PS_IDENTITY (effective, id_UNIT_GROUP, id_item_ps) values (?, ?, ?)
...
...
org.hibernate.exception.ConstraintViolationException: could not insert: [org.hibernate.test.PsIdentity]
...
Caused by: java.sql.SQLException: Cannot insert the value NULL into column 'id_item', table 'bopos.dbo.PS_IDENTITY'; column does not allow nulls. INSERT fails.
...
Note the code generated by hibernate for insert into PS_IDENTITY, it code not include the non null field id_item.
Code:
Hibernate: insert into bopos.dbo.PS_IDENTITY (effective, id_UNIT_GROUP, id_item_ps) values (?, ?, ?)
Please, any suggestion was appreciate.
Thanks.