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