Hibernate and update of only valorized fields

A

Alessandro

Hi all,

I have a problem with Hibernate: I need to call cyclically every xx minutes
an update of a record searched by primary key in a table (so only one
record) and with ONLY SOME updated fields.

Every time the table-field-mapping bean is created, I set only fields to be
updated, the other ones remains at "null" or with the initial value defined
in the bean constructor.

Result: updated correctly updates the record but fields not inside update
lose the last value and they get the initial one or null.

Poor solution: before update, call a select of the record and load all db
fields into bean

Other ideas ??

Many thanks for any help,
Best Regards

Alessandro
 
R

Roedy Green

What does "valorized" mean?
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Let us pray it is not so, or if it is, that it will not become widely known."
~ Wife of the Bishop of Exeter on hearing of Darwin's theory of the common descent of humans and apes.
 
J

Jean-Baptiste Nizet

Alessandro a écrit :
Hi all,

I have a problem with Hibernate: I need to call cyclically every xx minutes
an update of a record searched by primary key in a table (so only one
record) and with ONLY SOME updated fields.

Every time the table-field-mapping bean is created, I set only fields to be
updated, the other ones remains at "null" or with the initial value defined
in the bean constructor.

Result: updated correctly updates the record but fields not inside update
lose the last value and they get the initial one or null.

Of course. You tell Hibernate to persist a detached object, so Hibernate
persists the object. How would it know that you only want to persist
some of the fields of the objects? null or the initial value, whatever
it is, is a perfectly valid value to be stored in the database.

The solution is either to perform an update query (see
http://docs.jboss.org/hibernate/stable/core/reference/en/html/batch.html#batch-direct),
or to load/get the object, modify it and commit.

JB.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top