0

I have a parent A table that has a one-to-many relationship with a table B. In the file generated with Hibernate 3.6 version.

public class A {
private B firstChild;
private B secondChild;

When i save myParent "a":

firstObject = a.getFirstChild();
session.saveOrUpdate(firstObject);
session.saverOrUpdate(a);

i have Exception: object references an unsaved transient instance - save the transient instance before flushing

In my Parent POJO I have two instances of same Table (second record have a column with ID_relation value equal ID primary first record) example

a = Progressive ID 178, Name,  Surname, FK with B and ID_B ="1"
B first = ID sequence 1, Description , Price , ID REL null
B second = ID sequence 6, Description ,Price, ID REL ="1"

Thanks

  • Show how have you defined relations. – mentallurg Jan 24 '20 at 22:11
  • Try having `CascadeType.ALL` or saving the two B entities before saving the A entitiy. – Valentin Grégoire Jan 24 '20 at 22:52
  • Does this answer your question? [How to fix the Hibernate "object references an unsaved transient instance - save the transient instance before flushing" error](https://stackoverflow.com/questions/2302802/how-to-fix-the-hibernate-object-references-an-unsaved-transient-instance-save) – user2222 Jan 25 '20 at 00:00
  • https://stackoverflow.com/a/23606953/573032 – Roman C Jan 25 '20 at 12:42
  • Hi, while debuggin I founded "org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved" in my class Parent A I have a Pojo maps a Table with a FK , If I don't insert a record Address i have the error – user1361416 Jan 27 '20 at 14:20
  • Examples about map a single table to multiple classes are all refer Hibernate version 5, i am using older version 3.6 thanks a lots – user1361416 Jan 28 '20 at 09:14
  • Solved :-) I have another entity in class A which was an instance (class D has a relation with A with pk and fk) with all properties null. I must pass this entity with null so Hibernate works perfectly. So I don't want insert a record in D table and with Hibernate the entinty must be NULL. bye – user1361416 Jan 31 '20 at 13:10

0 Answers0