[JIRA] (HHH-16251) Hibernate Envers wrong modified flag on OneToMany relations
by Christophe Silon (JIRA)
Christophe Silon ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6401c2b... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZDU5ODgzMGUy... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16251?atlOrigin=eyJpIjoiZDU5OD... ) HHH-16251 ( https://hibernate.atlassian.net/browse/HHH-16251?atlOrigin=eyJpIjoiZDU5OD... ) Hibernate Envers wrong modified flag on OneToMany relations ( https://hibernate.atlassian.net/browse/HHH-16251?atlOrigin=eyJpIjoiZDU5OD... )
Issue Type: Bug Affects Versions: 5.3.28, 6.2.0.CR3 Assignee: Chris Cranford ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) Components: hibernate-envers Created: 03/Mar/2023 06:44 AM Environment: Java 17
database platform: postgreSql, h2
Priority: Major Reporter: Christophe Silon ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6401c2b... )
The values of the “_MOD” fields are incorrect in specific cases.
@Entity
@Table(name = "PERSON")
@Audited(withModifiedFlag = true)
public class PersonEntity {
@Id
@Column(name = "ID_PERSONNE")
private Long id;
@Column(name = "NAME", length = 100)
private String name;
@Audited( withModifiedFlag = true, modifiedColumnName = "SERVICES_MOD")
private Set<PersonneServiceEntity> services = new HashSet<>(); // Entity with attributs, gettters, setters and envers annotations...
@Audited( withModifiedFlag = true, modifiedColumnName = "OPT_INS_MOD")
private Set<OptinEntity> optIns = new HashSet<>();// Entity with attributs, gettters, setters and envers annotations...
// more fields
// + getters, setteurs, equals, tostring
The problem happens when you try in the same transaction, to modify in this example, the “ PersonEntity " entity (by modifying the name), and add an entity to multiple OneToMany relations (in the above example, if you add an entity into services and an entity into optIns ), the flag of the modified fields in the entity will be correct, but only the flag of the first collection modified will be set.
For example:
* Modify the name
* Add a PersonneServiceEntity to the services relation
* Add a OptinEntity to the optIns relation
When you check the values in the database, you will see that all the flag will be correctly set except the OPT_INS_MOD flag.
If you add a OptinEntity before the PersonneServiceEntity , then the OPT_INS_MOD flag will be set correctly but not the SERVICES_MOD flag.
If you don’t modify the name, then the flag of all collections will be set correctly.
(This is the same problem as https://stackoverflow.com/questions/64011351/hibernate-envers-wrong-modif... ( https://stackoverflow.com/questions/64011351/hibernate-envers-wrong-modif... ) )
( https://hibernate.atlassian.net/browse/HHH-16251#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16251#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#100217- sha1:65be9f2 )
1 year, 10 months
[JIRA] (HHH-16250) Mapping same column twice and one of them using a custom type leads to "Unknown wrap conversion requested"
by Jones (JIRA)
Jones ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNWZhYzg1MTg2... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16250?atlOrigin=eyJpIjoiNWZhYz... ) HHH-16250 ( https://hibernate.atlassian.net/browse/HHH-16250?atlOrigin=eyJpIjoiNWZhYz... ) Mapping same column twice and one of them using a custom type leads to "Unknown wrap conversion requested" ( https://hibernate.atlassian.net/browse/HHH-16250?atlOrigin=eyJpIjoiNWZhYz... )
Change By: Jones ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Given:
* A simple entity
* One attribute maps a jdbc VARCHAR to a SortedSet<Integer> using a custom user type
* Another attribute maps the very same VARCHAR column to a normal String field, but having it readonly (updatable=false and insertable=false)
When:
* When querying this entity
Then:
* An exception happens because hibernate mixes both properties java types
{noformat}@Entity
@Table(name = "MY_TABLE")
public class MyEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Integer id;
@Column(name = "SORTED_IDS")
@Type(org.hibernate.bugs.IntegerSetUserType.class)
private final SortedSet<Integer> sortedIds = new TreeSet<>();
@Column(name = "SORTED_IDS", updatable = false, insertable = false)
private String sortedIdsExpression;
public SortedSet<Integer> getSortedIds() {
return sortedIds;
}
}
// Add your tests, using standard JUnit.
@Test
public void hhh0000Test() throws Exception {
// BaseCoreFunctionalTestCase automatically creates the SessionFactory and
// provides the Session.
Session s = openSession();
Transaction tx = s.beginTransaction();
MyEntity entity = new MyEntity();
entity.getSortedIds().add(213);
entity.getSortedIds().add(324);
entity.getSortedIds().add(128);
s.persist(entity);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
Query<MyEntity> query = s.createQuery("from MyEntity e where e.sortedIdsExpression like :expression",
MyEntity.class);
query.setParameter("expression", "%|324|%");
List<MyEntity> actual = query.list();
assertThat(actual).hasSize(1);
tx.commit();
s.close();
}
jakarta.persistence.PersistenceException: Converting `org.hibernate.HibernateException` to JPA `PersistenceException` : Unknown wrap conversion requested: java.util.TreeSet to java.lang.String : `org.hibernate.type.descriptor.java.StringJavaType` (java.lang.String)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:165)
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:374)
at org.hibernate.query.sqm.internal.QuerySqmImpl.list(QuerySqmImpl.java:1073)
at org.hibernate.bugs.ORMUnitTestCase.hhh0000Test(ORMUnitTestCase.java:81)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.hibernate.HibernateException: Unknown wrap conversion requested: java.util.TreeSet to java.lang.String : `org.hibernate.type.descriptor.java.StringJavaType` (java.lang.String)
at org.hibernate.type.descriptor.java.JavaTypeHelper.unknownWrap(JavaTypeHelper.java:23)
at org.hibernate.type.descriptor.java.AbstractClassJavaType.unknownWrap(AbstractClassJavaType.java:115)
at org.hibernate.type.descriptor.java.StringJavaType.wrap(StringJavaType.java:103)
at org.hibernate.type.descriptor.java.StringJavaType.coerce(StringJavaType.java:121)
at org.hibernate.type.descriptor.java.StringJavaType.coerce(StringJavaType.java:27)
at org.hibernate.sql.results.graph.basic.CoercingResultAssembler.extractRawValue(CoercingResultAssembler.java:33)
at org.hibernate.sql.results.graph.basic.BasicResultAssembler.assemble(BasicResultAssembler.java:59)
at org.hibernate.sql.results.graph.DomainResultAssembler.assemble(DomainResultAssembler.java:33)
at org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.extractConcreteTypeStateValues(AbstractEntityInitializer.java:1037)
at org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.initializeEntity(AbstractEntityInitializer.java:831)
at org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.initializeInstance(AbstractEntityInitializer.java:787)
at org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(StandardRowReader.java:152)
at org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:97)
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:198)
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:33)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:443)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:166)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(JdbcSelectExecutorStandardImpl.java:91)
at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:31)
at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.lambda$new$0(ConcreteSqmSelectQueryPlan.java:113)
at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:335)
at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:276)
at org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:571)
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:363)
... 17 more
{noformat}
The only reason I need to map this column twice is:
* to be able to use it in HQL → {{e.sortedIdsExpression like :expression}}
This works fine in latest Hibernate 5
I’ll attach the test Test case as soon the Jira issue number is created attached and also available in my github repository [https://github. com/ratoaq2/HHH-16250|https://github.com/ratoaq2/HHH-16250|smart-link]
( https://hibernate.atlassian.net/browse/HHH-16250#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16250#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#100217- sha1:65be9f2 )
1 year, 10 months
[JIRA] (HHH-16250) Mapping same column twice and one of them using a custom type leads to "Unknown wrap conversion requested"
by Jones (JIRA)
Jones ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNmQ3YWViM2Ri... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16250?atlOrigin=eyJpIjoiNmQ3YW... ) HHH-16250 ( https://hibernate.atlassian.net/browse/HHH-16250?atlOrigin=eyJpIjoiNmQ3YW... ) Mapping same column twice and one of them using a custom type leads to "Unknown wrap conversion requested" ( https://hibernate.atlassian.net/browse/HHH-16250?atlOrigin=eyJpIjoiNmQ3YW... )
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Unassigned Components: hibernate-core Created: 03/Mar/2023 05:38 AM Priority: Major Reporter: Jones ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Given:
* A simple entity
* One attribute maps a jdbc VARCHAR to a SortedSet<Integer> using a custom user type
* Another attribute maps the very same VARCHAR column to a normal String field, but having it readonly (updatable=false and insertable=false)
When:
* When querying this entity
Then:
* An exception happens because hibernate mixes both properties java types
@Entity
@Table(name = "MY_TABLE")
public class MyEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Integer id;
@Column(name = "SORTED_IDS")
@Type(org.hibernate.bugs.IntegerSetUserType.class)
private final SortedSet<Integer> sortedIds = new TreeSet<>();
@Column(name = "SORTED_IDS", updatable = false, insertable = false)
private String sortedIdsExpression;
public SortedSet<Integer> getSortedIds() {
return sortedIds;
}
}
// Add your tests, using standard JUnit.
@Test
public void hhh0000Test() throws Exception {
// BaseCoreFunctionalTestCase automatically creates the SessionFactory and
// provides the Session.
Session s = openSession();
Transaction tx = s.beginTransaction();
MyEntity entity = new MyEntity();
entity.getSortedIds().add(213);
entity.getSortedIds().add(324);
entity.getSortedIds().add(128);
s.persist(entity);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
Query<MyEntity> query = s.createQuery("from MyEntity e where e.sortedIdsExpression like :expression",
MyEntity.class);
query.setParameter("expression", "%|324|%");
List<MyEntity> actual = query.list();
assertThat(actual).hasSize(1);
tx.commit();
s.close();
}
jakarta.persistence.PersistenceException: Converting `org.hibernate.HibernateException` to JPA `PersistenceException` : Unknown wrap conversion requested: java.util.TreeSet to java.lang.String : `org.hibernate.type.descriptor.java.StringJavaType` (java.lang.String)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:165)
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:374)
at org.hibernate.query.sqm.internal.QuerySqmImpl.list(QuerySqmImpl.java:1073)
at org.hibernate.bugs.ORMUnitTestCase.hhh0000Test(ORMUnitTestCase.java:81)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.hibernate.HibernateException: Unknown wrap conversion requested: java.util.TreeSet to java.lang.String : `org.hibernate.type.descriptor.java.StringJavaType` (java.lang.String)
at org.hibernate.type.descriptor.java.JavaTypeHelper.unknownWrap(JavaTypeHelper.java:23)
at org.hibernate.type.descriptor.java.AbstractClassJavaType.unknownWrap(AbstractClassJavaType.java:115)
at org.hibernate.type.descriptor.java.StringJavaType.wrap(StringJavaType.java:103)
at org.hibernate.type.descriptor.java.StringJavaType.coerce(StringJavaType.java:121)
at org.hibernate.type.descriptor.java.StringJavaType.coerce(StringJavaType.java:27)
at org.hibernate.sql.results.graph.basic.CoercingResultAssembler.extractRawValue(CoercingResultAssembler.java:33)
at org.hibernate.sql.results.graph.basic.BasicResultAssembler.assemble(BasicResultAssembler.java:59)
at org.hibernate.sql.results.graph.DomainResultAssembler.assemble(DomainResultAssembler.java:33)
at org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.extractConcreteTypeStateValues(AbstractEntityInitializer.java:1037)
at org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.initializeEntity(AbstractEntityInitializer.java:831)
at org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.initializeInstance(AbstractEntityInitializer.java:787)
at org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(StandardRowReader.java:152)
at org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:97)
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:198)
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:33)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:443)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:166)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(JdbcSelectExecutorStandardImpl.java:91)
at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:31)
at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.lambda$new$0(ConcreteSqmSelectQueryPlan.java:113)
at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:335)
at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:276)
at org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:571)
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:363)
... 17 more
The only reason I need to map this column twice is:
* to be able to use it in HQL → e.sortedIdsExpression like :expression
This works fine in latest Hibernate 5
I’ll attach the test case as soon the Jira issue number is created.
( https://hibernate.atlassian.net/browse/HHH-16250#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16250#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#100217- sha1:65be9f2 )
1 year, 10 months