• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating the Mapping Table.

 
Anil Suvarthan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I found this group to be very helpful with the issues i have got earlier.
Currently we are using Hibernate with Annotations. I am having a problem inserting the rows into a mapping table.

Tables:
Person(PersonId, PersonName)
Dept(DeptId, DeptName, personCreated)
PersonDept(PersonId, DeptId)

In Dept.java I have a mapping defined to retrieve the persons of that Dept.

@ManyToMany
@JoinTable( name="PersonDept"
joinColumns={@JoinColumn(name="DeptId")},
inverseJoinColumns={@JoinColumn(name="PersonId")}
)
public List<Person> findPersons() {
return persons;
}

I am trying to save a new Dept(in Dept table) with existing users to be assigned to the Dept (in PersonDept table).

When i set the values to the Dept class and save the class, it is giving the exception

org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: Person

I have given the cascade option @ManyToMany(cascade=CascadeType.PERSIST), but from the query i got to know that it is trying to save the Person which is not what i am expecting. I want to save a new Dept in the Dept table and the mappings in the PersonDept table with the personIds against the DeptId.

Can anyone help me out with this?

Regards,
Vasanth
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Vasanth"

Please click on the My Profile link above and change your display name to meet the JavaRanch Naming Policy of using your real first and real last names.

Thanks

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We need both real first and last names, not just one name. So for you it looks like "Anil Suvarthan"

Thanks

Mark
 
Anil Suvarthan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have updated the names.

And i've got this one working, it was an issue with the other field which was being updated which is not intended.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic