Christian Thiel (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZDk5ZDdlNTI5...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16682?atlOrigin=eyJpIjoiZDk5ZD...
) HHH-16682 (
https://hibernate.atlassian.net/browse/HHH-16682?atlOrigin=eyJpIjoiZDk5ZD...
) Changes in @JdbcTypeCode(SqlTypes.JSON) are not written to DB (
https://hibernate.atlassian.net/browse/HHH-16682?atlOrigin=eyJpIjoiZDk5ZD...
)
Issue Type: Bug Affects Versions: 6.2.1, 6.2.3 Assignee: Unassigned Attachments:
code-with-quarkus.zip Components: hibernate-core Created: 24/May/2023 01:51 AM
Environment: Quarkus 3.0.3 (integrates hibernate-orm 6.2.1-final)
Quarkus 3 SNAPHSOT with hibernate-orm 6.2.3 (see
https://github.com/Sanne/quarkus/tree/ORM6) Priority: Major Reporter: Christian Thiel (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%...
)
I have a JSON-Mapping in my entity
@Entity
public class MyEntity {
@Id
private Long id;
@JdbcTypeCode(SqlTypes.JSON)
private MyJson jsonProperty;
private String info;
}
MyJson is a simple POJO:
@Embeddable
public class MyJson {
private String stringProp;
private Long longProp;
}
If i change only the jsonProperty, it seems the entity is not marked dirty → changes are
not written to the DB.
If i change any other field-value to (in my test-case the String-field info ), the entity
is marked dirty and all changes are written to DB, even the JSON-changes.
(see MyEntityTest.java in attached Test-project):
@QuarkusTest
@Transactional(Transactional.TxType.REQUIRES_NEW)
class MyEntityTest {
@Inject
EntityManager em;
static final long PK = 123L;
static final String CHANGED = "CHANGED" ;
@Test
void shouldCreateUpdateAndSelectMyEntity() throws Exception {
insert();
findAndUpdate();
selectFiltered();
}
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);
}
void findAndUpdate() {
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
}
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" );
assertEquals(CHANGED, result.get(0).getInfo(), "plain property not
changed" );
}
}
(
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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:2b972a1 )