I have this bidirectional one-to-one association, but when I save the class 'usuario' (user), the column 'usuario' at 'professor' (teacher) is not updated. The user is created, the teacher is updated but the foreign key at teacher is still NULL.
Table Professor:Code:
CREATE TABLE ppgcc.professor
(
id_professor serial NOT NULL,
nome character varying(45) NOT NULL,
email character varying(45) NOT NULL,
website character varying(45),
usuario integer,
CONSTRAINT professor_pkey PRIMARY KEY (id_professor),
CONSTRAINT professor_usuario_fkey FOREIGN KEY (usuario)
REFERENCES ppgcc.usuario (id_usuario) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE SET NULL,
CONSTRAINT professor_usuario_key UNIQUE (usuario)
)
Table Usuario:Code:
CREATE TABLE ppgcc.usuario
(
id_usuario serial NOT NULL,
login character varying(45) NOT NULL,
senha character varying(45) NOT NULL,
acesso integer NOT NULL,
CONSTRAINT usuario_pkey PRIMARY KEY (id_usuario),
CONSTRAINT usuario_login_key UNIQUE (login)
)
Professor Mapping:Code:
<class name="Professor" schema="ppgcc" table="professor">
<id name="id" type="int" column="id_professor">
<generator class="identity"/>
</id>
<many-to-one name="usuario" class="Usuario" fetch="select" column="usuario" unique="true"/>
<property name="nome" type="string" length="45" column="nome" not-null="true"/>
<property name="email" type="string" length="45" column="email" not-null="true"/>
<property name="website" type="string" length="45" column="website"/>
</class>
Usuario Mapping:Code:
<class name="Usuario" table="usuario" schema="ppgcc">
<id name="id" type="int" column="id_usuario">
<generator class="identity" />
</id>
<property name="login" type="string" column="login" length="45" not-null="true" unique="true"/>
<property name="senha" type="string" column="senha" length="45" not-null="true"/>
<property name="acesso" type="int" column="acesso" not-null="true"/>
<one-to-one name="professor" class="Professor" property-ref="usuario" cascade="save-update"/>
</class>
When saving usuario Hibernate does this:Hibernate: insert into ppgcc.usuario (login, senha, acesso) values (?, ?, ?)
Hibernate: select currval('ppgcc.usuario_id_usuario_seq')
Hibernate: update ppgcc.professor set usuario=?, nome=?, email=?, website=? where id_professor=?
The strange thing is that it updates the teacher(professor) but in time to get the id of the user(usuario) it is coming NULL.
I am using Postgres.
Thanks for any help.