• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TransientObjectException

 
Venkat Babu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have two tables, Address and person

Mapping for Address to Person is one-to-many.

I have this example but it is not working, I am getting org.hibernate.TransientObjectException: hibernate.Person

could someone help pls?

tx = session.beginTransaction();
Address addr = new Address();
addr.setAddress1("123 Victoria Dr");
addr.setAddress2 ("Apt 213");
addr.setCity("Ashburn");
addr.setState("GA");
addr.setZip("83782");
//Create person 1
Person person = new Person();
person.setFirstName ("Paul");
person.setLastName("Douglas");

Set personsSet = new HashSet();
//Associate to the address
personsSet.add(person);
//create person 2 and associate to the address
Person person2 = new Person();
person2.setFirstName("John");
person2.setLastName("Smith");
personsSet.add(person2);
addr.setPersons(personsSet);
session.saveOrUpdate(addr);



Thanks
 
Ravindra Rawat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See following for bidirectional relationship.

http://www.hibernate.org/hib_docs/reference/en/html/tutorial.html

Section 1.3.6
 
Jinesh Parekh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use cascade=all in your mapping and it will save all the rechable objects.
 
Venkat Babu
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome. It worked. Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic