Do updates to ejb3 entity objects only update new values?

Do updates to ejb3 entity objects only update new values?

Post by Keit » Fri, 24 Nov 2006 07:18:09


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
 
 
 

Do updates to ejb3 entity objects only update new values?

Post by Wesley Hal » Fri, 24 Nov 2006 09:39:23


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.

 
 
 

Do updates to ejb3 entity objects only update new values?

Post by Keit » Fri, 24 Nov 2006 10:16:34

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