Jpa2 force em to update field set as insertable = false

I am working with jpa 2.0 and I have a field in my database table that has a default value, I put this field in my entity definition as insertable = false so that when the default is inserted, the insert is done correctly, but when the object is queried that the field is essentially null, however that it was inserted correctly.

This is my code:

@Entity
@Table(name="SOME_TABLE")
public class SomeTable implements Serializable {
private static final long serialVersionUID = 1L;

@EmbeddedId
private SomeTablePK id;

@Column(name="X1")
private String x1;

**@Column(name="X2", insertable=false)**
private Date x2;

... more fields....

... setters and getters...
}

      

Is there a way to force the object manager to update the value of the field I used as insertable = false? or what can I do to fix this?

Many thanks.

PS. It is important to note that in my persistence.xml and put the following line to disable the cache.

<properties>
<property name="javax.persistence.sharedCache.mode" value="NONE"/>
</properties>

      

+3


source to share


1 answer


You will need to manually activate the update after the cleanup operation.

The specification ( 3.2.4 Database Synchronization ) says that:

The state of persistent objects is synchronized with the database when a transaction is committed. This synchronization involves writing to the database any updates to persistent objects and their relationships as noted above.

Updating the state of an object includes both assigning a new value to a constant property and an object field, as well as changing the mutable value of a constant property or field [28].



Please note below:

Database synchronization is not associated with updating any managed objects, unless the update operation is explicitly invoked on these entities or cascaded to them as a result of the specification of a cascade member = REFRESH or cascade = ALL value.

+4


source







All Articles