[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-3609) Invalid list re-ordering with IndexColumn and OneToMany association

Gail Badner (JIRA) noreply at atlassian.com
Tue Jul 20 17:32:35 EDT 2010


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3609?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gail Badner resolved HHH-3609.
------------------------------

      Assignee: Gail Badner
    Resolution: Duplicate

> Invalid list re-ordering with IndexColumn and OneToMany association
> -------------------------------------------------------------------
>
>                 Key: HHH-3609
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3609
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.3.1
>         Environment: Hibernate 3.3.1, Hibernate Tools 3.2.0, H2 database 1.0.69
>            Reporter: Martin Kovacik
>            Assignee: Gail Badner
>
> I want to map unidirectional OneToMany ordered list using annotations. My mapping is:
> public class Invoice {
> // ...
> @OneToMany(cascade = CascadeType.ALL)
> 	@JoinTable(
> 	    name = "INVOICE_ITEM",
> 	    joinColumns = {@JoinColumn(name = "invoice_id")},
> 	    inverseJoinColumns = {@JoinColumn(name = "item_id")}
> 	)
> 	@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
> 	@IndexColumn(name = "item_order")
> 	private List<Item> items = new ArrayList<Item>();
> 	
> }
> The mapping of Item is not important here because I just want the association from Invoice to collection of Items to be unidirectional.
> The problem what hbm2ddl generates:
> create table INVOICE_ITEM (
> 	invoice_id int8 not null,
> 	item_id int8 not null,
> 	item_order int4 not null,
> 	primary key (invoice_id, item_order),
> 	unique (item_id)
> );
> alter table INVOICE_ITEM 
> 	add constraint FK89837AD3EDA329D 
> 	foreign key (item_id) 
> 	references ITEM;
> alter table INVOICE_ITEM 
> 	add constraint FK89837AD76A8E2D7 
> 	foreign key (invoice_id) 
> 	references INVOICE;
> 	
> Another problem is how hibernate handles list re-ordering. If I want to change the item order (by manipulating invoice.items list) and then persist the changes hibernate tries to execute following sql:
> update
> 	INVOICE_ITEM 
> set
> 	item_id=2 
> where
> 	invoice_id=1
> 	and item_order=0
> 	
> update
> 	INVOICE_ITEM 
> set
> 	item_id=1
> where
> 	invoice_id=1
> 	and item_order=1
> However this causes DB to complain about unique item_id constraint (which was generated by hibernate). IMHO hibernate should update just the item_order column.
> I think that this bug is related to ANN-679 (http://opensource.atlassian.com/projects/hibernate/browse/ANN-679).

-- 
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