-->
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.  [ 2 posts ] 
Author Message
 Post subject: Update: How to resolve?
PostPosted: Wed Sep 01, 2004 1:13 pm 
Beginner
Beginner

Joined: Wed Jan 21, 2004 10:52 pm
Posts: 27
Location: Santa Cruz do Sul - RS - Brazil
Hibernate version:
2.1.1
Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
none
Name and version of the database you are using:
Postgres 7.4
Debug level Hibernate log excerpt:
none

Hi all,
I'm using Hibernate in 3tier architecture with objects loaded in one session and saved(uptaded) in another.
The problem occur when I update/save one object.
I have an object (the Car class) that have an attribute engine (the Engine class). When I load the car (ex. car.id=100) the engine attribute is null (car.engine=null). Then, in GUI, the user select an engine for this car in a JComboBox. Each element of JComboBox model is a tuple of "id" (Long) and "name" (String) of Engine (not an engine object, because its big and only relevant properties are loaded in JComboBox).
The cascades options between car and engine are "save-update".
Then, the client code to save/update is:
Code:

//currentCar was loaded in one session from app server.
currentCar.setColor(jtxtCarColor.getText());

//Get selected id of engine and create an engine object with this id
Long idSelected = (Long) ((Object[]) jcmbCarEngine.getSelectedItem())[0];
Engine engineSelected = new Engine();
engineSelected.setId(idSelected);

//Update engine property in currentCar
currentCar.setEngine(engineSelected);

//Store car
persistence.saveOrUpdate(currentCar);


The update ocours with succes for "currentCar", but (obviously) the "engineSelected" are updated too and its properties are lost (setted with null) in db.

My question is: How to update "currentCar" but not lost "engineCar" properties in db using this approach?

_________________
Do you still create DTO factories? Oh, no!
Try DTOptimzier now!
https://dtoptimizer.dev.java.net/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 01, 2004 5:41 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you can load first the engine with the given id and then call myCar.setEngine(loadedEngine)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.