I have a parent class Person which maps table Person(pid). I have a subclass called User which maps table User(pid, username). Their mapping is 'joined-subclass'. Now, i have one record in Person, say pid=2. I want to insert a new record User(2,'test').
however, if I do like this:
Person p = session.load(Person.class, pid);
User u = new User();
u.setPid(p.getPid());
u.setUsername("test");
session.save(u);
I got this error:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
if i do session.merge(u), i got this error:
org.hibernate.WrongClassException: Object with id: null was not of the specified subclass:
Any idea?
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
[b]Hibernate version:[/b]
[b]Mapping documents:[/b]
[b]Code between sessionFactory.openSession() and session.close():[/b]
[b]Full stack trace of any exception that occurs:[/b]
[b]Name and version of the database you are using:[/b]
[b]The generated SQL (show_sql=true):[/b]
[b]Debug level Hibernate log excerpt:[/b]
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html