[JIRA] (HHH-14000) Allow a custom Type that was registered via TypeContributions to be resolved by its class, not just its name
by Vlad Mihalcea (JIRA)
Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOGZkZDU4N2E1... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiOGZkZD... ) HHH-14000 ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiOGZkZD... ) Allow a custom Type that was registered via TypeContributions to be resolved by its class, not just its name ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiOGZkZD... )
Change By: Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
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 {{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}javax.persistence.PersistenceException: org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1542)
at org.hibernate.query.Query.getResultList(Query.java:165)
at org.hibernate.test.type.contributor.ArrayTypeContributorTest.lambda$testNativeSQL$5(ArrayTypeContributorTest.java:99){noformat}
That’s because the {{Array}}property is resolved by {{SerializableType}} instead of {{ArrayType}}.
( https://hibernate.atlassian.net/browse/HHH-14000#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14000#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#100125- sha1:927dd36 )
5 years, 7 months
[JIRA] (HHH-14000) Allow a custom Type that was registered via Type Contributors to be resolved by its class, not just its name
by Vlad Mihalcea (JIRA)
Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYmVmN2M4MWIy... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiYmVmN2... ) HHH-14000 ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiYmVmN2... ) 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=eyJpIjoiYmVmN2... )
Change By: Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
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 {{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}javax.persistence.PersistenceException: org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1542)
at org.hibernate.query.Query.getResultList(Query.java:165)
at org.hibernate.test.type.contributor.ArrayTypeContributorTest.lambda$testNativeSQL$5(ArrayTypeContributorTest.java:99){noformat}
That’s because the {{Array}}property is resolved by {{SerializableType}} instead of {{ArrayType}}.
( https://hibernate.atlassian.net/browse/HHH-14000#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14000#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#100125- sha1:927dd36 )
5 years, 7 months
[JIRA] (HHH-14000) Allow a custom Type that was registered via Type Contributors to be resolved by its class, not just its name
by Vlad Mihalcea (JIRA)
Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMjJmNTVhNDg5... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiMjJmNT... ) HHH-14000 ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiMjJmNT... ) 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=eyJpIjoiMjJmNT... )
Change By: Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
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=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14000#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#100125- sha1:927dd36 )
5 years, 7 months
[JIRA] (HHH-14000) A "Could not locate appropriate constructor on class" is thrown when calling JPA createNativeQuery(String sqlString, String resultSetMapping)
by Vlad Mihalcea (JIRA)
Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZjA2OTdkM2M3... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiZjA2OT... ) HHH-14000 ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiZjA2OT... ) A "Could not locate appropriate constructor on class" is thrown when calling JPA createNativeQuery(String sqlString, String resultSetMapping) ( https://hibernate.atlassian.net/browse/HHH-14000?atlOrigin=eyJpIjoiZjA2OT... )
Issue Type: Bug Affects Versions: 5.4.15 Assignee: Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) Components: hibernate-core Created: 04/May/2020 03:50 AM Fix Versions: 5.4.16 Priority: Major Reporter: Vlad Mihalcea ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
When calling the following query:
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();
Where the emailAddresses uses a custom Typ and the result set mapping is mapped like this:
@SqlResultSetMapping(
name = "CorporateUserDTO" ,
classes = @ConstructorResult(
targetClass = CorporateUserDTO.class,
columns = {
@ColumnResult(name = "userName" ),
@ColumnResult(name = "emailAddresses" , type = Array.class),
}
)
)
The following exception is thrown:
java.lang.IllegalArgumentException: Could not locate appropriate constructor on class : org.hibernate.test.type.contributor.ArrayTypeContributorTest$CorporateUserDTO
at org.hibernate.loader.custom.ConstructorResultColumnProcessor.resolveConstructor(ConstructorResultColumnProcessor.java:92)
at org.hibernate.loader.custom.ConstructorResultColumnProcessor.performDiscovery(ConstructorResultColumnProcessor.java:45)
at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:494)
at org.hibernate.loader.Loader.processResultSet(Loader.java:2338)
It looks like the Constructor is resolved using the Hibernate Type instead of the actual Java Type.
( https://hibernate.atlassian.net/browse/HHH-14000#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14000#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#100125- sha1:927dd36 )
5 years, 7 months
[JIRA] (HSEARCH-3909) Restore support for looking up the capabilities of each field in the metamodel
by Yoann Rodière (JIRA)
Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate Search ( https://hibernate.atlassian.net/browse/HSEARCH?atlOrigin=eyJpIjoiMDI4MDlm... ) / Task ( https://hibernate.atlassian.net/browse/HSEARCH-3909?atlOrigin=eyJpIjoiMDI... ) HSEARCH-3909 ( https://hibernate.atlassian.net/browse/HSEARCH-3909?atlOrigin=eyJpIjoiMDI... ) Restore support for looking up the capabilities of each field in the metamodel ( https://hibernate.atlassian.net/browse/HSEARCH-3909?atlOrigin=eyJpIjoiMDI... )
Change By: Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
I.e. we need a way to know which predicates/sorts/projections/etc. are available for a given field. This will make it possible to implement something similar to jpamodelgen, where classes are generated at compile-time to represent the index metamodel and can be used in the Search DSL (something that's been [requested before|https://discourse.hibernate.org/t/hsearch-metamodel/3915]).
There was (limited) support for that in Search 5, through {{org.hibernate.search.metadata.FieldSettingsDescriptor#getType}}, {{org.hibernate.search.metadata.FieldSettingsDescriptor#getIndex}}, {{org.hibernate.search.metadata.FieldSettingsDescriptor#getStore}}.
An interesting way to implement this would be through a {{hasCapability(String)}} methods, where the string is the name of a given capability: match predicate, "within circle" predicate, "field value" sort, "distance" sort, ... Names would be exposed as constants in some {{BuiltinCapabilities}} class, and more importantly **each backend could define additional constants for its extended capabilities**. This would be very similar to what is described in HSEARCH-3633 for field configuration.
This ticket is a follow-up on HSEARCH-3589.
( https://hibernate.atlassian.net/browse/HSEARCH-3909#add-comment?atlOrigin... ) Add Comment ( https://hibernate.atlassian.net/browse/HSEARCH-3909#add-comment?atlOrigin... )
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#100125- sha1:927dd36 )
5 years, 7 months