Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Updating the Mapping Table.

 
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
 
ranger
Posts: 17346
11
Mac IntelliJ IDE 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
Posts: 17346
11
Mac IntelliJ IDE 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.
 
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic