-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Bidirectional one-to-one save problem
PostPosted: Sun Mar 06, 2011 1:39 am 
Newbie

Joined: Sat Mar 05, 2011 8:52 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.