[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-723) Impossible to bind a SortedMap collection
David Mansfield (JIRA)
noreply at atlassian.com
Mon Aug 25 09:48:27 EDT 2008
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-723?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30991 ]
David Mansfield commented on ANN-723:
-------------------------------------
is there any way to get feedback on this issue. it should be trivial to fix, it's an obvious bug introduced in a stable release, and now another stable release has gone out the door. is there anything I can do?
> Impossible to bind a SortedMap collection
> -----------------------------------------
>
> Key: ANN-723
> URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-723
> Project: Hibernate Annotations
> Issue Type: Bug
> Affects Versions: 3.3.0.ga
> Environment: hibernate: 3.2.5.ga
> hibernate-annotations: 3.3.0.ga
> database: HSQL 1.8.0.7
> Reporter: Alexandre Dutra
> Assignee: Hardy Ferentschik
> Priority: Minor
> Fix For: 3.3.2, 3.4.0.CR2
>
> Original Estimate: 2 days
> Remaining Estimate: 2 days
>
> See http://forum.hibernate.org/viewtopic.php?t=976437
> I have the following collection declared in a persistent class:
> @CollectionOfElements
> @Sort(type = SortType.NATURAL)
> @JoinTable(name = "delivery_option_price", joinColumns = @JoinColumn(name = "delivery_option_id"))
> private SortedMap<Float, MonetaryAmount> prices = new TreeMap<Float, MonetaryAmount>();
> Hibernate fails to bind it to a database table. The stack trace is:
> java.lang.NullPointerException
> at org.hibernate.cfg.annotations.MapBinder.bindKeyFromAssociationTable(MapBinder.java:129)
> at org.hibernate.cfg.annotations.MapBinder.access$000(MapBinder.java:53)
> at org.hibernate.cfg.annotations.MapBinder$1.secondPass(MapBinder.java:83)
> at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
> at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
> at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
> at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
> at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
> ...
> A workaround to this is to explicitly specify the map key class by adding a org.hibernate.annotations.MapKey annotation:
> @org.hibernate.annotations.MapKey(targetElement = Float.class, columns = @Column(name = "WEIGHT"))
> Browsing the source code, I realized that the NullPointerException is being raised beacause the following method returns null in org.hibernate.annotations.common.reflection.java.JavaXCollectionType:
> public XClass getMapKey() {
> return new TypeSwitch<XClass>() {
> @Override
> public XClass caseParameterizedType(ParameterizedType parameterizedType) {
> if ( getCollectionClass().isAssignableFrom( Map.class ) ) {
> return toXClass( parameterizedType.getActualTypeArguments()[0] );
> }
> return null;
> }
> }.doSwitch( approximate() );
> }
> More specifically, the following expression seems misconstructed:
> getCollectionClass().isAssignableFrom( Map.class )
> The correct expression would be:
> Map.class.isAssignableFrom( getCollectionClass() )
> At least if, as I understand it, the goal is to determine whether the collection class is or is not a Map in anyone one of its implementations. The same applies to the getElementClass() method, in the same class.
> If my analyzis is correct, the bug might be very easy to fix, but maybe I'm underestimating its impacts.
--
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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list