Message:
The following issue has been closed.
Resolver: Gavin King
Date: Tue, 16 Sep 2003 8:52 PM
This is expected functionality. There have been many discussions about why this is virtually impossible to do "better", given Hibernate's support for detached objects.
---------------------------------------------------------------------
View the issue:
http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-336
Here is an overview of the issue:
---------------------------------------------------------------------
Key: HB-336
Summary: composite id index generation in one-to-many association
Type: Bug
Status: Closed
Priority: Major
Resolution: REJECTED
Project: Hibernate2
Versions:
2.1 beta 3
Assignee:
Reporter: Antonio martos
Created: Tue, 16 Sep 2003 3:48 AM
Updated: Tue, 16 Sep 2003 8:52 PM
Environment: Hibernate 2.1 beta 3b, J2SDK 1.4.1, Oracle 9.2.0.1
Description:
I have 2 persistent classes (Parent.class and Child.class), that are associated by a one to many relationship. The child
class has a composite id as its Primary Key. This composite id has 2 fields: the first one is Foreign Key of a field from the
Parent and the second one is an index field. I create a collection child data (list) and add it to the parent, and try to
persist all (save). The problem is that my index is NOT automatically generated, and so I have to specify it manually each
time I add a child. I suspect that the problem is that my index is also part of the primary key of the child class, because
when I've worked with other relations with index columns that are not primary key (or part of) of the corresponding tables,
hibernate generates the index automatically following the order given in the Collection.
If you don't specify the value of the index, you'll see that hibernate tells you that you can't give a null value to that
field (just like if it wasn't generated)
This is the implementation of the one to many relationship between both classes (mapped to two tables). The Parent one has a
Primary Key composed of one field of type integer, just like this:
<hibernate-mapping>
<class
name="es.Parent"
table="PARENT"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="reportId"
column="REPORT_ID"
type="java.lang.Integer"
>
<generator class="assigned">
</generator>
</id>
....
</class>
</hibernate-mapping>
In the Parent xml mapping file, this is the implementation used specifying the relation:
<list
name="children"
lazy="false"
inverse="true"
cascade="all"
>
<key
column="REPORT_ID"
/>
<index
column="SEQ_NUMBER"
/>
<one-to-many
class="es.Child"
/>
</list>
The Child class has a composite-id composed by a Foreign key (Primary Key of the Parent class) and a sequence number (index
of the relationship):
<hibernate-mapping>
<class
name="es.Child"
table="CHILDREN"
dynamic-update="false"
dynamic-insert="false"
>
<composite-id
name="children_id"
class="es.ChildId"
unsaved-value="any"
>
<key-property
name="sequenceNumber"
type="java.lang.Integer"
column="SEQ_NUMBER"
/>
<key-many-to-one
name="report"
class="es.Parent"
column="REPORT_ID"
/>
</composite-id>
... child properties ....
</class>
</hibernate-mapping>
I've looked for an answer in faqs and in the document reference and I've found nothing related to this issue.
Thank you.
---------------------------------------------------------------------
JIRA INFORMATION:
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
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
|