java.lang.NullPointerException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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.
    via by Alexandre Dutra,
  • 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.
    via by Alexandre Dutra,
  • I got: [java] Exception in thread "main" java.lang.ExceptionInInitializerError [java] at util.HibernateUtil.<clinit>(Unknown Source) [java] at one.Start.main(Unknown Source) [java] Caused by: java.lang.NullPointerException [java] at org.hibernate.cfg.AnnotationBinder.bindOneToOne(AnnotationBinder.java:1960) [java] at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1346) [java] at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.java:1731) [java] at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1768) [java] at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1229) [java] at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733) [java] at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498) [java] at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277) [java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286) [java] at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915) [java] ... 2 more when I tried to run application where i have @OneToOne in composite key (@ManyToOne worked fine) I made this code as short as I could, just put path to jars in build.xml and to database in hibernate.cfg.xml if you want to check it If I upload to much or to few just let me know, couse it's first time i'm adding stuff here I'm posting it because emmanuel told me to do it :)
    via by Artur Legan,
  • I got: [java] Exception in thread "main" java.lang.ExceptionInInitializerError [java] at util.HibernateUtil.<clinit>(Unknown Source) [java] at one.Start.main(Unknown Source) [java] Caused by: java.lang.NullPointerException [java] at org.hibernate.cfg.AnnotationBinder.bindOneToOne(AnnotationBinder.java:1960) [java] at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1346) [java] at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.java:1731) [java] at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1768) [java] at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1229) [java] at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733) [java] at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498) [java] at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277) [java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286) [java] at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915) [java] ... 2 more when I tried to run application where i have @OneToOne in composite key (@ManyToOne worked fine) I made this code as short as I could, just put path to jars in build.xml and to database in hibernate.cfg.xml if you want to check it If I upload to much or to few just let me know, couse it's first time i'm adding stuff here I'm posting it because emmanuel told me to do it :)
    via by Artur Legan,
  • Context initialization failed
    via by Sesha Sathish,
    • 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)
    No Bugmate found.