Hibernate version:
3.1
Mapping documents:
Code:
<class name="User" table="users" schema="public">
<id name="cod">
<column name="userid" not-null="true"/>
<generator class="sequence">
<param name="sequence">usuarios_usuarioid_seq</param>
</generator>
</id>
<property name="name" type="string">
<column name="name" />
</property>
<property name="passwd" type="string">
<column name="passwd" />
</property>
</class>
<joined-subclass name="Teacher" table="teacher" extends="User">
<key column="userid" />
<bag name="colDisciplinas" table="disciplinasprofessores" lazy="true">
<key column="userid" />
<many-to-many class="Discipline" column="disciplineid"/>
</bag>
</joined-subclass>
Hi there!
First, sorry if my english is bad.
Now, the problem.
I'm having an issue with a joined-subclass. I have an user table and a teacher table. A teacher is also a user, so Teacher extends User, and I'm using the table-per-subclass strategy. Also there's many-to-many mapping in the Teacher class.
It's working smootly when loading is involved, so I assume there's no critical error in the mapping.
The thing is when I try to insert a teacher.
In the system, a teacher register itself, so I insert it in the user table. The system don't know yet if this user will be a teacher.
After that, the admin of the system can change the user role, marking him as a teacher, so I insert a line in the teacher table. But when I do that, Hibernate also insert a line in the user table, assuming it's a new user, but that's not the case, since I already have an user with that id. As a result of this, I get 2 lines in the user table with the same data.
Is there a way to make Hibernate think 'look, I already have an user with that id, so I will just insert it in the teachers table'??
In any case, thanks in advance :).