-->
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.  [ 1 post ] 
Author Message
 Post subject: ManyToOne combined with PrimaryKey
PostPosted: Tue Jul 11, 2006 5:03 am 
Newbie

Joined: Tue May 16, 2006 12:49 pm
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2CR1

Hi!

I've got some questions concerning this subject.

I've got a simple relation: one document consisting of several bookings.

Code:
public class Document {
  @Id
  private Long id;
}

public class Booking {

  @EmbeddedId
  private BookingPk pk;

}

public class BookingPk {

  @ManyToOne
  private Document document;

  private int sequenceNumber; // for each document, start with 1

}


Now, everything works just fine - except that I didn't define a biderectional mapping. So I say
Code:
public class Document {
  @Id
  private Long id;
  @ManyToOne(mappedBy="pk.document")
  private List<Booking> bookings;
}

which doesn't work because Hibernate claims: org.hibernate.AnnotationException: mappedBy reference an unknown property: net.paybox.mobiliser.sva.model.Booking.pk.document in net.paybox.mobiliser.sva.model.Document.pk.document.
Unfortunately, using "document" doesn't work either.

So my first question is: How can I map this relation correctly?

Then I tried to change the owning side:
Code:
public class Document {
  @Id
  private Long id;
  @ManyToOne
  @JoinColumn(name="ID_DOC")
  private List<Booking> bookings;
}

Now, I manage to compile and even save bookings attached to the doc by simply saving the doc. Unfortunately, Hibernate first inserts the bookings and afterwards updates the ID_DOC field - which is rather ridiculous because it executes:
Code:
UPDATE BOOKINGS SET ID_DOC=42 WHERE ID_DOC=42 AND ID_SEQ=1


So my second question is: How can I prevent Hibernate from performing these updates?

Any help is appreciated!

Sebastian


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

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.