-->
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: Simple Many-to-one question - Unexpected behaviour?
PostPosted: Wed Nov 08, 2006 9:59 am 
Newbie

Joined: Wed Nov 08, 2006 8:50 am
Posts: 13
Hi, I am having a problem related to many-to-one mappings. I have three classes in a situation that Preco has a many-to-one relationship with Custo, which has a set of Preco and also a many-to-one to Tipo which also has a set of Custo. Everything is working fine, I can retrieve the values from the classes and save each of them individually without problems.

What I am trying to do is something like this (all the instances of Preco, Custo and Tipo exist)

Preco preco = session.load(Preco.class, precoId);

Custo custo = preco.getCusto();

//=> trying to change the Tipo from Custo
custo.getTipo.setId(new Integer(tipoId));

session.save(preco);

I think you can get the picture now, what I am trying to do is to get the existent Custo from Preco and change the existent Tipo from Custo, and persist this. I am having no success on doing that, I get no errors, and if I change any properties of Custo (not many-to-one, simple properties) they are persisted as well, but the many-to-one property change is not persisted. If I do like this, however, it works:


Preco preco = session.load(Preco.class, precoId);

Custo custo = preco.getCusto();

Tipo tipo = new Tipo(new Integer(tipoId));

custo.setTipo(tipo);

session.save(preco);

Is this an expected behavior? Should it work the other way?

Thanks a lot.


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.