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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100217- sha1:65be9f2 )