Do updates to ejb3 entity objects only update new values?

K

Keith

Hello,

Let's say an entity object is selected representing a row in a
database. If one of the fields is changed in the ejb3 object and then
persisted, will all the fields be updated in the database, or only the
one that change?

Thank,
Ed
 
W

Wesley Hall

Keith said:
Hello,

Let's say an entity object is selected representing a row in a
database. If one of the fields is changed in the ejb3 object and then
persisted, will all the fields be updated in the database, or only the
one that change?

Thank,
Ed


A very good question.

I suspect that it depends on your implementation of the entity manager
but most likely is that all fields are in the resulting SQL whether they
have changed or not. With EJB3, POJO based entities there are no
application server generated files like with EJB 2x.

With EJB2x the container generated the actually concrete implementation
and could therefore inject code that would detect which fields have
changed. EJB3 is based on reflection which makes this detection more
difficult (but not impossible).

It should be a problem as the update will occur in a single SQL
statement regardless but if for some reason this makes a big difference
in your application I can only suggest you run a trace on your database
and look at the SQL. I don't believe the spec is clear on how updates
should be performed leaving the decision to the implementer. If this is
the case, be aware that any reliance on a particular behaviour may not
be portable between entity manager providers.
 
K

Keith

Thank You for your response.

It is important to us that only the column that changed be updated...
we have triggers set on each field to fire and load an event table. We
only want to write an event when a particular column changed. If all
columns are updated regardless if the actual value changed, this will
write event table entries that do not actually reflect a change in a
field.

Ed
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top