[JIRA] (HHH-15733) @Convert on Map should not require "attributeName=value"
by Hansi B (JIRA)
Hansi B ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63736b9... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMDEyNTliMDQx... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiMDEyNT... ) HHH-15733 ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiMDEyNT... ) @Convert on Map should not require "attributeName=value" ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiMDEyNT... )
Change By: Hansi B ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63736b9... )
This entity definition with an *@ElementCollection* and a *@Convert* on a *Map* attribute results in a runtime exception:
{code:java}@Entity
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int id;
@ElementCollection
@Convert(converter = MyStringConverter.class)
private Map<String, String> responsibilities = new HashMap<>();
void put(String key, String value) {
responsibilities.put(key, value);
}
String get(String key) {
return responsibilities.get(key);
}
}{code}
The exception points to the says it requires an * Convert attributeName * annotation on the *Map* for this :
{noformat}Caused by: java.lang.IllegalStateException: @Convert placed on Map attribute [org.hibernate.bugs.Employee.responsibilities] must define attributeName of 'key' or 'value'
at org.hibernate.cfg.CollectionPropertyHolder.applyLocalConvert(CollectionPropertyHolder.java:133)
at org.hibernate.cfg.CollectionPropertyHolder.buildAttributeConversionInfoMaps(CollectionPropertyHolder.java:88)
at org.hibernate.cfg.CollectionPropertyHolder.prepare(CollectionPropertyHolder.java:379){noformat}
Indeed, the code in *CollectionPropertyHolder* explicitly enforces this, and a comment states:
{noformat}// ... JPA says
// that @Convert on a Map always needs to specify attributeName of key/value (or prefixed with
// key./value. for embedded paths).{noformat}
However, this does not appear to be the case: While the standard lists a few cases which require an *attributeName* on a *Map*, it does not require *attributeName* on a *Map* of basic types; without *attributeName*, the conversion should be applied on the values in the *Map*. See, e.g., "Example 5" on [https://docs.jboss.org/hibernate/jpa/2.2/api/javax/persistence/Convert.ht...]
{noformat}Example 5: Apply a converter to an element collection that is a map or basic values.
The converter is applied to the map value.
@ElementCollection
@Convert(converter=EmployeeNameConverter.class)
Map<String, String> responsibilities;{noformat}
(This is identical to Example 5 in the Java TM Persistence API, Version 2.2, Chapter 11.1.10. , minus the typo. )
One could even go a step further and say that *attributeName="value"* should be forbidden on *Map*s with basic type values, since the standard specifies:
{noformat}The Convert annotation may be applied to a basic attribute or to an element collection of basic type
(in which case the converter is applied to the elements of the collection). In these cases, the
attributeName element must not be specified.{noformat}
(Indeed, Eclipselink will raise an exception when *attributeName="value"* is specified on a *Map* with values of a basic type.)
I have seen this behaviour when using the Entity in a minimal test (just create an Employee) both in the *hibernate-test-case-templates/orm/hibernate-orm-5* and *hibernate-test-case-templates/orm/hibernate-orm-6*
The problem does not occur without the *@ElementCollection*.
( https://hibernate.atlassian.net/browse/HHH-15733#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15733#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#100210- sha1:9b34d7c )
3 years, 5 months
[JIRA] (HHH-15733) @Convert on Map should not require "attributeName=value"
by Hansi B (JIRA)
Hansi B ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63736b9... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzg0YWExOGMy... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiNzg0YW... ) HHH-15733 ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiNzg0YW... ) @Convert on Map should not require "attributeName=value" ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiNzg0YW... )
Change By: Hansi B ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63736b9... )
This entity definition results in a runtime exception:
{code:java}@Entity
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int id;
@ElementCollection
@Convert(converter = MyStringConverter.class)
private Map<String, String> responsibilities = new HashMap<>();
void put(String key, String value) {
responsibilities.put(key, value);
}
String get(String key) {
return responsibilities.get(key);
}
}{code}
The exception points to the *Convert* annotation on the *Map*:
{noformat}Caused by: java.lang.IllegalStateException: @Convert placed on Map attribute [org.hibernate.bugs.Employee.responsibilities] must define attributeName of 'key' or 'value'
at org.hibernate.cfg.CollectionPropertyHolder.applyLocalConvert(CollectionPropertyHolder.java:133)
at org.hibernate.cfg.CollectionPropertyHolder.buildAttributeConversionInfoMaps(CollectionPropertyHolder.java:88)
at org.hibernate.cfg.CollectionPropertyHolder.prepare(CollectionPropertyHolder.java:379){noformat}
Indeed, the code in *CollectionPropertyHolder* explicitly enforces this, and a comment states:
{noformat}// ... JPA says
// that @Convert on a Map always needs to specify attributeName of key/value (or prefixed with
// key./value. for embedded paths).{noformat}
However, this does not appear to be the case: While the standard lists a few cases which require an *attributeName* on a *Map*, it does not require *attributeName* on a *Map* of basic types; without *attributeName*, the conversion should be applied on the values in the *Map*. See, e.g., "Example 5" on [https://docs.jboss.org/hibernate/jpa/2.2/api/javax/persistence/Convert.ht...]
{noformat}Example 5: Apply a converter to an element collection that is a map or basic values.
The converter is applied to the map value.
@ElementCollection
@Convert(converter=EmployeeNameConverter.class)
Map<String, String> responsibilities;{noformat}
(This is identical to Example 5 in the Java TM Persistence API, Version 2.2, Chapter 11.1.10.)
One could even go a step further and say that *attributeName="value"* should be forbidden on *Map*s with basic type values, since the standard specifies:
{noformat}The Convert annotation may be applied to a basic attribute or to an element collection of basic type
(in which case the converter is applied to the elements of the collection). In these cases, the
attributeName element must not be specified.{noformat}
(Indeed, Eclipselink will raise an exception when *attributeName="value"* is specified on a *Map* with values of a basic type.)
I have seen this behaviour when using the Entity in a minimal test (just create an Employee) both in the *hibernate-test-case-templates/orm/hibernate-orm-5* and *hibernate-test-case-templates/orm/hibernate-orm-6*
The problem does not occur without the *@ElementCollection*.
( https://hibernate.atlassian.net/browse/HHH-15733#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15733#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#100210- sha1:9b34d7c )
3 years, 5 months
[JIRA] (HHH-15733) @Convert on Map should not require "attributeName=value"
by Hansi B (JIRA)
Hansi B ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63736b9... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYWJlYjE4NjE1... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiYWJlYj... ) HHH-15733 ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiYWJlYj... ) @Convert on Map should not require "attributeName=value" ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiYWJlYj... )
Change By: Hansi B ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63736b9... )
This entity definition results in a runtime exception:
{code:java}
@Entity
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int id;
@ElementCollection
@Convert(converter = MyStringConverter.class)
private Map<String, String> responsibilities = new HashMap<>();
void put(String key, String value) {
responsibilities.put(key, value);
}
String get(String key) {
return responsibilities.get(key);
}
}
{code}
The exception points to the * Convert - * annotation on the * Map * :
{noformat}
Caused by: java.lang.IllegalStateException: @Convert placed on Map attribute [org.hibernate.bugs.Employee.responsibilities] must define attributeName of 'key' or 'value'
at org.hibernate.cfg.CollectionPropertyHolder.applyLocalConvert(CollectionPropertyHolder.java:133)
at org.hibernate.cfg.CollectionPropertyHolder.buildAttributeConversionInfoMaps(CollectionPropertyHolder.java:88)
at org.hibernate.cfg.CollectionPropertyHolder.prepare(CollectionPropertyHolder.java:379)
{noformat}
Indeed, the code in * CollectionPropertyHolder * explicitly enforces this, and a comment states:
{noformat}
// ... JPA says
// that @Convert on a Map always needs to specify attributeName of key/value (or prefixed with
// key./value. for embedded paths).
{noformat}
However, this does not appear to be the case: While the standard lists a few cases which require an " * attributeName " * on a * Map * , it does not require " * attributeName " * on a * Map * of basic types; without " * attributeName " * , the conversion should be applied on the values in the * Map *. See, e.g., "Example 5" on [ https://docs.jboss.org/hibernate/jpa/2.2/api/javax/persistence/Convert.html: |https://docs.jboss.org/hibernate/jpa/2.2/api/javax/persistence/Convert.html:]
{noformat}
Example 5: Apply a converter to an element collection that is a map or basic values.
The converter is applied to the map value.
@ElementCollection
@Convert(converter=EmployeeNameConverter.class)
Map<String, String> responsibilities;
{noformat}
(This is identical to Example 5 in the Java TM Persistence API, Version 2.2, Chapter 11.1.10.)
One could even go a step further and say that * attributeName="value" * should be forbidden on Maps *Map*s with basic type values, since the standard specifies:
{noformat}
The Convert annotation may be applied to a basic attribute or to an element collection of basic type
(in which case the converter is applied to the elements of the collection). In these cases, the
attributeName element must not be specified.
{noformat}
(Indeed, Eclipselink will raise an exception when * attributeName="value" * is specified on a * Map * with values of a basic type.)
I have seen this behaviour when using the Entity in a minimal test (just create an Employee) both in the *hibernate-test-case-templates/orm/hibernate-orm-5* and *hibernate-test-case-templates/orm/hibernate-orm-6*
( https://hibernate.atlassian.net/browse/HHH-15733#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15733#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#100210- sha1:9b34d7c )
3 years, 5 months
[JIRA] (HHH-15733) @Convert on Map should not require "attributeName=value"
by Hansi B (JIRA)
Hansi B ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63736b9... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNjA4Y2U2NDBj... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiNjA4Y2... ) HHH-15733 ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiNjA4Y2... ) @Convert on Map should not require "attributeName=value" ( https://hibernate.atlassian.net/browse/HHH-15733?atlOrigin=eyJpIjoiNjA4Y2... )
Issue Type: Bug Affects Versions: 6.1.5, 5.6.14 Assignee: Unassigned Components: hibernate-core Created: 17/Nov/2022 11:42 AM Priority: Major Reporter: Hansi B ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63736b9... )
This entity definition results in a runtime exception:
@Entity
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int id;
@ElementCollection
@Convert(converter = MyStringConverter.class)
private Map< String , String > responsibilities = new HashMap<>();
void put( String key, String value) {
responsibilities.put(key, value);
}
String get( String key) {
return responsibilities.get(key);
}
}
The exception points to the Convert-annotation on the Map:
Caused by: java.lang.IllegalStateException: @Convert placed on Map attribute [org.hibernate.bugs.Employee.responsibilities] must define attributeName of 'key' or 'value'
at org.hibernate.cfg.CollectionPropertyHolder.applyLocalConvert(CollectionPropertyHolder.java:133)
at org.hibernate.cfg.CollectionPropertyHolder.buildAttributeConversionInfoMaps(CollectionPropertyHolder.java:88)
at org.hibernate.cfg.CollectionPropertyHolder.prepare(CollectionPropertyHolder.java:379)
Indeed, the code in CollectionPropertyHolder explicitly enforces this, and a comment states:
// ... JPA says
// that @Convert on a Map always needs to specify attributeName of key/value (or prefixed with
// key./value. for embedded paths).
However, this does not appear to be the case: While the standard lists a few cases which require an "attributeName" on a Map, it does not require "attributeName" on a Map of basic types; without "attributeName", the conversion should be applied on the values in the Map. See, e.g., "Example 5" on https://docs.jboss.org/hibernate/jpa/2.2/api/javax/persistence/Convert.html: ( https://docs.jboss.org/hibernate/jpa/2.2/api/javax/persistence/Convert.html: )
Example 5: Apply a converter to an element collection that is a map or basic values.
The converter is applied to the map value.
@ElementCollection
@Convert(converter=EmployeeNameConverter.class)
Map<String, String> responsibilities;
(This is identical to Example 5 in the Java TM Persistence API, Version 2.2, Chapter 11.1.10.)
One could even go a step further and say that attributeName="value" should be forbidden on Maps with basic type values, since the standard specifies:
The Convert annotation may be applied to a basic attribute or to an element collection of basic type
(in which case the converter is applied to the elements of the collection). In these cases, the
attributeName element must not be specified.
(Indeed, Eclipselink will raise an exception when attributeName="value" is specified on a Map with values of a basic type.)
( https://hibernate.atlassian.net/browse/HHH-15733#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15733#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#100210- sha1:9b34d7c )
3 years, 5 months