-->
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.  [ 3 posts ] 
Author Message
 Post subject: updating 1-1 relation a new record is added on child item
PostPosted: Mon Oct 10, 2011 5:26 pm 
Beginner
Beginner

Joined: Sun Jan 30, 2011 8:14 am
Posts: 24
Dear all,
I've a great issue with hibernate, with annotated classes.
I've a 1 - relationship (i've this issue also with 1-n relationship) between user and role, that is a user must have one and one only role.
In my User class I've

Code:
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="ID_ROLE)
private Role            cRole;


Clicking on Save button I check if it's a new user or existing one.

// save if new, if not update
Code:
if(this.m_cObject==null)
{
         cUserDao.create(cUser);
} else {
         long id=((User)m_cObject).getIdUser();
         cUser.setIdUtente(id);
         cUserDao.update(cUser);
}


cUserDao.update(cUser) calls this method

Code:
protected void saveOrUpdate(Object obj) {
        try {
            startOperation();
            session.saveOrUpdate(obj);
            tx.commit();

        } catch (HibernateException e) {
            System.out.println("Errore nel salvataggio oggetto : "+e.getMessage());
            handleException(e);
        } finally {
            HibernateFactory.close(session);
        }
    }


with

Code:
protected void startOperation() throws HibernateException {
        session = HibernateFactory.openSession();
        tx = session.beginTransaction();
    }


Result is this one:
When I edit user and I change role and save it, user is correctly update and also role si updated, but a new row for role is added.
I noted the same one on 1-n relationship, father of relationship is correctly updated, but for child ones a new row is added.
Why it?
Could you help me?
Please, thanks


Top
 Profile  
 
 Post subject: Re: updating 1-1 relation a new record is added on child item
PostPosted: Tue Oct 11, 2011 7:35 am 
Beginner
Beginner

Joined: Sun Jan 30, 2011 8:14 am
Posts: 24
No one could help me?
Do you need more detail?
Please let me know, I can't solve it and I didn't find any help on the net..


Top
 Profile  
 
 Post subject: Re: updating 1-1 relation a new record is added on child item
PostPosted: Thu Oct 13, 2011 7:45 am 
Beginner
Beginner

Joined: Sun Jan 30, 2011 8:14 am
Posts: 24
I thinked to add correct level of detail...is'nt any reply on my issue?
Nobody can help me?
I found many issues on net without any reply...why?
Could someone help me?
Thanks


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

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.