-->
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: [OneToOne] Ownee obj has ID = 0! Cannot correctly update.
PostPosted: Fri Jul 06, 2007 9:33 am 
Newbie

Joined: Fri Feb 23, 2007 12:42 pm
Posts: 5
Hello there,
I'm trying to update two object related between eachother by a OneToOne relation. Everytime I try to update these object a new "ownee" record is created in the RDBMS instead of updating the existing one. The error seems to be related by the the ownee's id, which on the select results to be equals to 0 (other ownee's properties are ok and visible).
I'd appreciate any help from you.
Belowe some details, including some code.
Thanks in advance.


Hibernate version: 3.2.3

Mapping documents:

Code between sessionFactory.openSession() and session.close():
Code:
public Usr getUsrById(long id) {
        Usr user = null;
        user = em.find(Usr.class,new Long(id));
        return user;
    }
...
@TransactionAttribute(TransactionAttributeType.REQUIRED)
    public boolean update(Usr user) throws Exception {
        if(this.check(user)){
            em.merge(user);
            return true;
        }else return false;
    }


Name and version of the database you are using: MySql 5

The generated SQL (show_sql=true):
Quote:
14:43:52,196 INFO [STDOUT] Hibernate:
select
usr0_.id as id14_2_,
usr0_.password as password14_2_,
usr0_.username as username14_2_,
usr0_.regDate as regDate14_2_,
usr0_.email as email14_2_,
usr0_.verificationLink as verifica7_14_2_,
usr0_.active as active14_2_,
usr0_.skills as skills14_2_,
usr0_.minEuroSalary as minEuro10_14_2_,
usr0_.minSterlSalary as minSter11_14_2_,
usr0_.idealJob as idealJob14_2_,
usr0_.cvUriPath as cvUriPath14_2_,
usr0_.availPeriod as availPe14_14_2_,
usr0_.user_type as user1_14_2_,
addresslis1_.user_fk_id as user17_4_,
addresslis1_.id as id4_,
addresslis1_.id as id15_0_,
addresslis1_.address as address15_0_,
addresslis1_.companyName as companyN3_15_0_,
addresslis1_.title as title15_0_,
addresslis1_.firstName as firstName15_0_,
addresslis1_.lastName as lastName15_0_,
addresslis1_.city as city15_0_,
addresslis1_.postalCode as postalCode15_0_,
addresslis1_.stateOrProvince as stateOrP9_15_0_,
addresslis1_.countryOrRegion as country10_15_0_,
addresslis1_.phoneNumber as phoneNu11_15_0_,
addresslis1_.faxNumber as faxNumber15_0_,
addresslis1_.mobileNumber as mobileN13_15_0_,
addresslis1_.notes as notes15_0_,
addresslis1_.vat as vat15_0_,
addresslis1_.website as website15_0_,
addresslis1_.user_fk_id as user17_15_0_,
usrrole2_.id as id16_1_,
usrrole2_.username as username16_1_,
usrrole2_.userRole as userRole16_1_
from
USR usr0_
left outer join
USR_ADDRESS addresslis1_
on usr0_.id=addresslis1_.user_fk_id
left outer join
USR_ROLE usrrole2_
on usr0_.id=usrrole2_.id
where
usr0_.id=?
order by
14:43:52,196 INFO [STDOUT] Hibernate:
select
usr0_.id as id14_2_,
usr0_.password as password14_2_,
usr0_.username as username14_2_,
usr0_.regDate as regDate14_2_,
usr0_.email as email14_2_,
usr0_.verificationLink as verifica7_14_2_,
usr0_.active as active14_2_,
usr0_.skills as skills14_2_,
usr0_.minEuroSalary as minEuro10_14_2_,
usr0_.minSterlSalary as minSter11_14_2_,
usr0_.idealJob as idealJob14_2_,
usr0_.cvUriPath as cvUriPath14_2_,
usr0_.availPeriod as availPe14_14_2_,
usr0_.user_type as user1_14_2_,
addresslis1_.user_fk_id as user17_4_,
addresslis1_.id as id4_,
addresslis1_.id as id15_0_,
addresslis1_.address as address15_0_,
addresslis1_.companyName as companyN3_15_0_,
addresslis1_.title as title15_0_,
addresslis1_.firstName as firstName15_0_,
addresslis1_.lastName as lastName15_0_,
addresslis1_.city as city15_0_,
addresslis1_.postalCode as postalCode15_0_,
addresslis1_.stateOrProvince as stateOrP9_15_0_,
addresslis1_.countryOrRegion as country10_15_0_,
addresslis1_.phoneNumber as phoneNu11_15_0_,
addresslis1_.faxNumber as faxNumber15_0_,
addresslis1_.mobileNumber as mobileN13_15_0_,
addresslis1_.notes as notes15_0_,
addresslis1_.vat as vat15_0_,
addresslis1_.website as website15_0_,
addresslis1_.user_fk_id as user17_15_0_,
usrrole2_.id as id16_1_,
usrrole2_.username as username16_1_,
usrrole2_.userRole as userRole16_1_
from
USR usr0_
left outer join
USR_ADDRESS addresslis1_
on usr0_.id=addresslis1_.user_fk_id
left outer join
USR_ROLE usrrole2_
on usr0_.id=usrrole2_.id
where
usr0_.id=?
order by
addresslis1_.address asc
addresslis1_.address asc



"Owner" class
Code:
public class Usr implements java.io.Serializable {
...
@Id
    @GeneratedValue
    @Column()
    public long getId() {
        return id;
    }
...
@OneToOne(cascade = CascadeType.ALL)
    @PrimaryKeyJoinColumn
    public UsrRole getUserRole() {
        return userRole;
    }


Ownee class
Code:
public class UsrRole implements java.io.Serializable {
...
@Id
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }


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.