1

I want make an insert in the table EmployeebyProject, when try to insert throw the transient object exception.

Table EmployeebyProject : {PK: EmployeeId, PK: ProjectId, DateBegin, DateEnd}

This is the mapping:

<composite-id>
  <key-many-to-one name="Project" column="ProjectId" class="Project" cascade="save"></key-many-to-one>
  <key-many-to-one name="Employee" column="EmployeeId" class="Employee"></key-many-to-one>
</composite-id>

<property name="DateBegin" type="DateTime"/>
<property name="DateEnd" type="DateTime"/>

enter code here

How can avoid this problem?

1 Answer 1

1

Object from hibernate perspective can be in several states - transient, attached, detached ... Transient means entity that wasnt saved to the database yet. If i have relation A->B you need to save B in order to save A (because hibernate need to know what to put in A foreign key to B).

So 2 options:

  1. save B before. In your case Project, Employee
  2. put cascade . In your case you missing cascade on Employee
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.