These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Bidirectional indexed 1-n relation with composite keys
PostPosted: Mon Sep 28, 2009 4:31 am 
Regular
Regular

Joined: Wed Oct 15, 2003 4:40 pm
Posts: 67
I have a pretty standard master-detail relationship with an indexed collection and composite primary keys:

Code:
@Embeddable
public class InvoiceKey implements Serializable {
   private String customer;
   private int invoiceNumber;
...
}


Code:
@Embeddable
public class InvoiceRowKey implements Serializable {
   private String customer;
   private int invoiceNumber;
   private int rowNumber;
...
}


Code:
@Entity
public class Invoice {
   @Id
   private InvoiceKey invoiceKey;

   @OneToMany(cascade=CascadeType.ALL)
   @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
   @org.hibernate.annotations.IndexColumn(name="rowNumber", base=1)
   @JoinColumns({
         @JoinColumn(name="customer", referencedColumnName="customer"),
         @JoinColumn(name="invoiceNumber", referencedColumnName="invoiceNumber")
   })
   private List<InvoiceRow> invoiceRows = new ArrayList<InvoiceRow>();
...
}


Code:
@Entity
public class InvoiceRow {
   @Id
   private InvoiceRowKey orderRowKey;

   @ManyToOne
   private Invoice invoice;
...
}   


The invoice row number is updated nicely but when I remove a row in the middle I get

Code:
Hibernate: update InvoiceRow set customer=null, invoiceNumber=null, rowNumber=null where customer=? and invoiceNumber=? and customer=? and invoiceNumber=? and rowNumber=?
Hibernate: update InvoiceRow set customer=null, invoiceNumber=null, rowNumber=null where customer=? and invoiceNumber=? and customer=? and invoiceNumber=? and rowNumber=?
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update


resulting from the nulling of the primary key values in the invoice row.

Should the relation be mapped from the other invoice row side? Some nullable/insertable needed somewhere? I'm on 3.2

Grateful for assistance,
Nik


Top
 Profile  
 
 Post subject: Re: Bidirectional indexed 1-n relation with composite keys
PostPosted: Mon Sep 28, 2009 4:38 am 
Regular
Regular

Joined: Wed Oct 15, 2003 4:40 pm
Posts: 67
Ngh, sorry for the post, found one permutation that I hadn't tried before: mapping the relation from the invoice row side and setting null/insert/update all to false...


Top
 Profile  
 
 Post subject: Re: Bidirectional indexed 1-n relation with composite keys
PostPosted: Mon Sep 28, 2009 6:06 am 
Regular
Regular

Joined: Wed Oct 15, 2003 4:40 pm
Posts: 67
It appears as if I rejoiced a bit too early.

With the mapping from collection side I end up with a join table, something I'd rather not have.

So suggestions on this topic is still appreciated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.