java.lang.NullPointerException

Hibernate JIRA | Alexandre Dutra | 9 years ago
  1. 0

    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.

    Hibernate JIRA | 9 years ago | Alexandre Dutra
    java.lang.NullPointerException
  2. 0

    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.

    Hibernate JIRA | 9 years ago | Alexandre Dutra
    java.lang.NullPointerException
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Hibernate: Cannot create entity manager factory after connection reset

    Stack Overflow | 6 years ago | John
    java.lang.NullPointerException
  5. 0

    Creating composite key with manytomany mapping in hibernate

    Stack Overflow | 1 year ago | Sharique
    java.lang.NullPointerException

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.hibernate.cfg.annotations.MapBinder.bindKeyFromAssociationTable()
    2. Hibernate
      AnnotationConfiguration.buildSessionFactory
      1. org.hibernate.cfg.annotations.MapBinder.bindKeyFromAssociationTable(MapBinder.java:129)
      2. org.hibernate.cfg.annotations.MapBinder.access$000(MapBinder.java:53)
      3. org.hibernate.cfg.annotations.MapBinder$1.secondPass(MapBinder.java:83)
      4. org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
      5. org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
      6. org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
      7. org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
      8. org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
      8 frames