[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2946?page=c...
]
Sylvain Charton commented on HHH-2946:
--------------------------------------
It seems to me that when having a @AttributeOverride annotation on a Map<String,?>,
then Hibernate is taking the _properties_ of the key class (String) as index, instead of
the object itself.
Example:
@CollectionOfElements
@JoinTable(name="Clf_BinaryPublishingTemplateMapping",
joinColumns=@JoinColumn(name = "classifiedId", nullable=false,
updatable=false))
@AttributeOverride(name="element.value",
column=@Column(name="BinaryId"))
@MapKey(columns=@Column(name="PublishingTemplateRef", nullable=false,
updatable=false))
private Map<String, String> binaryPathPublishingTemplateMapping ;
If I remove the @AttributeOverride annotation, then the index property of the collection
definition in Hibernate is a single value String (see
AbstractCollectionPersister.java:349)
If I set the @AttributeOverride annotation, then the index property of the collection has
4 fields (value, offset, count, hash) which are the properties of the String class. Here
Hibernate takes the properties of the String instead of the String itself as key for the
Map.
It looks the same problem described above: Hibernate tries to use the bytes property of
the String class, because it found the getBytes() method, which is interpreted as an
getter for the property, but without setter, what causes the exception.
So the problem here is really: @AttributeOverride on an Indexed Collection.
@AttributeOverride of column type or name results in
PropertyNotFoundException
------------------------------------------------------------------------------
Key: HHH-2946
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2946
Project: Hibernate3
Issue Type: Bug
Environment: Hibernate 3.2.5.ga, Annotations 3.3.0.ga, Spring 2.0.7, MySQL
5.0.41-community-nt, Windows Vista
Reporter: Juan Antonio Agudo
Attachments: hibernateErrorTest.zip
When trying to map a java.util.Map<String,String> hibernate by default creates
VARCHAR(256) fields. When an attempt to alter for e.g. the column type to "TEXT"
an Exception is thrown. For example:
@CollectionOfElements
@AttributeOverride(name="element.value",
column=@Column(columnDefinition="TEXT"))
public Map<String, String> getSettings() {
return settings;
}
results in
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'sessionFactory' defined in file
[C:\Users\tag\workspace\xyz\conf\applicationContext.xml]: Invocation of init method
failed; nested exception is org.hibernate.PropertyNotFoundException: Could not find a
setter for property bytes in class java.lang.String
Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property
bytes in class java.lang.String
at
org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:216)
at
org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:209)
at org.hibernate.mapping.Property.getSetter(Property.java:277)
at
org.hibernate.tuple.component.PojoComponentTuplizer.buildSetter(PojoComponentTuplizer.java:137)
at
org.hibernate.tuple.component.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:44)
at
org.hibernate.tuple.component.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:38)
at
org.hibernate.tuple.component.ComponentEntityModeToTuplizerMapping.<init>(ComponentEntityModeToTuplizerMapping.java:52)
at
org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:50)
at org.hibernate.mapping.Component.buildType(Component.java:152)
at org.hibernate.mapping.Component.getType(Component.java:145)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Collection.validate(Collection.java:278)
at org.hibernate.mapping.IndexedCollection.validate(IndexedCollection.java:67)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1106)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
at
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
This behaviour can be reproduced and was described fully in
http://forum.hibernate.org/viewtopic.php?p=2368889#2368889
I attached an isolated sample code for review purposes.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira