[JIRA] (HHH-16682) Changes in @JdbcTypeCode(SqlTypes.JSON) are not written to DB
by Christian Thiel (JIRA)
Christian Thiel ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... ) *commented* on HHH-16682 ( https://hibernate.atlassian.net/browse/HHH-16682?atlOrigin=eyJpIjoiNGY4OD... )
Re: Changes in @JdbcTypeCode(SqlTypes.JSON) are not written to DB ( https://hibernate.atlassian.net/browse/HHH-16682?atlOrigin=eyJpIjoiNGY4OD... )
I don’t think the transaction is suspended. If i change my test as follows (each method excpet the test itself is annotated with @Transactional(Transactional.TxType.REQUIRES_NEW) ):
@Test
public void shouldCreateUpdateAndSelectMyEntity() throws Exception {
insert();
findAndUpdate();
selectFiltered();
}
@Transactional(Transactional.TxType.REQUIRES_NEW)
public void insert() {
MyEntity myEntity = new MyEntity();
myEntity.setId(PK);
MyJson myJson = new MyJson();
myJson.setLongProp(100L);
myJson.setStringProp( "Hello" );
myEntity.setJsonProperty(myJson);
em.persist(myEntity);
}
@Transactional(Transactional.TxType.REQUIRES_NEW)
public void findAndUpdate() throws Exception {
MyEntity found = em.find(MyEntity.class, PK);
found.getJsonProperty().setStringProp(CHANGED);
}
@Transactional(Transactional.TxType.REQUIRES_NEW)
public void selectFiltered() {
List<MyEntity> result = em
.createQuery( "SELECT e FROM MyEntity e WHERE e.jsonProperty.longProp = :x" , MyEntity.class)
.setParameter( "x" , 100L)
.getResultList();
assertEquals(1, result.size());
assertEquals(CHANGED, result.get(0).getJsonProperty().getStringProp(), "json property not changed" );
}
And step over the methods and select after each method with an external sql-navigator-tool , what’s currently in the DB, i find immediatly after the insert my data as expected in the table. So it seems the transaction was commited after the insert-method was done. I expect the new transactio for the findAndUpdate-Method to do likewise.
Another hint: Even if i change the findAndUpdate-Method to force a flush
@Transactional(Transactional.TxType.REQUIRES_NEW)
public void findAndUpdate() throws Exception {
MyEntity found = em.find(MyEntity.class, PK);
found.getJsonProperty().setStringProp(CHANGED);
em.flush();
}
Nothing is changed on the DB. I assume it’s because the flush is here a no-op operation (for hibernate entity is not dirty → no update necessary)
If i force the entity to be considered dirty by manipulating the other ‘info’-property
@Transactional(Transactional.TxType.REQUIRES_NEW)
public void findAndUpdate() throws Exception {
MyEntity found = em.find(MyEntity.class, PK);
found.getJsonProperty().setStringProp(CHANGED);
found.setInfo(CHANGED); // by changing any other property of the entity, it will be marked as dirty and EVERY change will be written to the DB
}
and again step through the methods, if see the changes fo json and info in the DB using the external SQL-tool, immediatly after ‘findAndUpdate’ has been finished.
( https://hibernate.atlassian.net/browse/HHH-16682#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16682#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:40c4da4 )