[hibernate-issues] [JIRA] (HHH-14000) Allow a custom Type that was registered via Type Contributors to be resolved by its class, not just its name

Vlad Mihalcea (JIRA) jira at hibernate.atlassian.net
Mon May 4 07:40:12 EDT 2020


Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Af5e8c0d3-3aae-4bb4-a4e1-25463d60d232 ) *updated* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMjJmNTVhNDg5YzM4NDE2MTkxMDI0OThiZGY1MDU4ZmIiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiMjJmNTVhNDg5YzM4NDE2MTkxMDI0OThiZGY1MDU4ZmIiLCJwIjoiaiJ9 ) HHH-14000 ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiMjJmNTVhNDg5YzM4NDE2MTkxMDI0OThiZGY1MDU4ZmIiLCJwIjoiaiJ9 ) Allow a custom Type that was registered via Type Contributors to be resolved by its class, not just its name ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiMjJmNTVhNDg5YzM4NDE2MTkxMDI0OThiZGY1MDU4ZmIiLCJwIjoiaiJ9 )

Change By: Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Af5e8c0d3-3aae-4bb4-a4e1-25463d60d232 )

Considering we have a custom Type we register like this:

{noformat}@Override
protected void addConfigOptions(Map options) {
options.put(
EntityManagerFactoryBuilderImpl.METADATA_BUILDER_CONTRIBUTOR,
(MetadataBuilderContributor) metadataBuilder ->
metadataBuilder.applyTypes( (typeContributions, serviceRegistry) -> {
typeContributions.contributeType( ArrayType.INSTANCE );
} ));
}{noformat}

When calling the following query:

{code:java}
List<CorporateUserDTO> emails = entityManager.createNativeQuery(
"select " +
" u.userName as userName, " +
" u.emailAddresses as emailAddresses " +
"from CorporateUser u " +
"where u.userName = :name", "CorporateUserDTO" )
.setParameter( "name", "Vlad" )
.getResultList();
{code}

Where the emailAddresses uses a custom Typ and the {{CorporateUserDTO}} result set mapping is mapped like this:

{code:java}
@SqlResultSetMapping(
name = "CorporateUserDTO",
classes = @ConstructorResult(
targetClass = CorporateUserDTO.class,
columns = {
@ColumnResult(name = "userName"),
@ColumnResult(name = "emailAddresses", type = Array.class),
}
)
)
{code}

The following exception is thrown:

{noformat}
java javax. lang persistence. IllegalArgumentException PersistenceException : Could not locate appropriate constructor on class : org.hibernate. test. type. contributor.ArrayTypeContributorTest$CorporateUserDTO SerializationException: could not deserialize

at org.hibernate. loader internal. custom ExceptionConverterImpl. ConstructorResultColumnProcessor.resolveConstructor convert ( ConstructorResultColumnProcessor ExceptionConverterImpl.java: 92 154 )
at org.hibernate. loader query. custom internal. ConstructorResultColumnProcessor AbstractProducedQuery. performDiscovery list ( ConstructorResultColumnProcessor AbstractProducedQuery.java: 45 1542 )
at org.hibernate. loader query. custom Query. CustomLoader.autoDiscoverTypes getResultList ( CustomLoader Query.java: 494 165 )
at org.hibernate. loader test. Loader type. processResultSet contributor.ArrayTypeContributorTest.lambda$testNativeSQL$5 ( Loader ArrayTypeContributorTest.java: 2338 99 )
{noformat}

It looks like That’s because the Constructor {{Array}}property is resolved using the Hibernate Type by {{SerializableType}} instead of the actual Java Type {{ArrayType}}.

( https://hibernate.atlassian.net/browse/HHH-14000#add-comment?atlOrigin=eyJpIjoiMjJmNTVhNDg5YzM4NDE2MTkxMDI0OThiZGY1MDU4ZmIiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14000#add-comment?atlOrigin=eyJpIjoiMjJmNTVhNDg5YzM4NDE2MTkxMDI0OThiZGY1MDU4ZmIiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:927dd36 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200504/8b86bcc2/attachment.html 


More information about the hibernate-issues mailing list