-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: NullPointerException from AnnotationConfiguration
PostPosted: Wed Apr 18, 2007 3:16 pm 
Newbie

Joined: Mon Apr 16, 2007 5:52 pm
Posts: 13
I've found a bug in AnnotationConfiguration that causes a NullPointerException.

Hibernate Annotations version:
3.3.0 GA

Hibernate version:
3.2.3 GA

Mapping documents:
orm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
    xmlns="http://java.sun.com/xml/ns/persistence/orm"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
    version="1.0">
</entity-mappings>
(Yes, it is empty)

example/Main.java
Code:
package example;

import org.hibernate.cfg.AnnotationConfiguration;

public class Main {
  public static void main(String[] args) {
    AnnotationConfiguration config  = new AnnotationConfiguration();
    config.addResource("orm.xml");
    config.addPackage("example");
  }
}

example/package-info.java
Code:
@GenericGenerator(name = "myGenerator", strategy = "sequence")
package example;

import org.hibernate.annotations.GenericGenerator;

Full stack trace of any exception that occurs:
Code:
Exception in thread "main" java.lang.NullPointerException
   at org.hibernate.cfg.annotations.reflection.EJB3OverridenAnnotationReader.initAnnotations(EJB3OverridenAnnotationReader.java:360)
   at org.hibernate.cfg.annotations.reflection.EJB3OverridenAnnotationReader.isAnnotationPresent(EJB3OverridenAnnotationReader.java:263)
   at org.hibernate.annotations.common.reflection.java.JavaXAnnotatedElement.isAnnotationPresent(JavaXAnnotatedElement.java:43)
   at org.hibernate.cfg.AnnotationBinder.bindPackage(AnnotationBinder.java:220)
   at org.hibernate.cfg.AnnotationConfiguration.addPackage(AnnotationConfiguration.java:165)
   at example.Main.main(Main.java:9)


Name and version of the database you are using:
N/A

The generated SQL (show_sql=true):
N/A

Debug level Hibernate log excerpt:
Code:
2007-04-18 14:59:05,419 [main] INFO  org.hibernate.cfg.annotations.Version:15 - Hibernate Annotations 3.3.0.GA
2007-04-18 14:59:05,451 [main] INFO  org.hibernate.cfg.Environment:509 - Hibernate 3.2.3
2007-04-18 14:59:05,451 [main] INFO  org.hibernate.cfg.Environment:542 - hibernate.properties not found
2007-04-18 14:59:05,451 [main] INFO  org.hibernate.cfg.Environment:676 - Bytecode provider name : cglib
2007-04-18 14:59:05,466 [main] INFO  org.hibernate.cfg.Environment:593 - using JDK 1.4 java.sql.Timestamp handling
2007-04-18 14:59:05,560 [main] INFO  org.hibernate.cfg.Configuration:553 - Reading mappings from resource : orm.xml
2007-04-18 14:59:05,669 [main] DEBUG org.hibernate.util.DTDEntityResolver:38 - trying to resolve system-id [file:///C:/dev/intellijprojects/hibernate-examples/orm_1_0.xsd]
2007-04-18 14:59:05,669 [main] DEBUG org.hibernate.cfg.EJB3DTDEntityResolver:31 - recognized EJB3 ORM namespace; attempting to resolve on classpath under org/hibernate/ejb
2007-04-18 14:59:05,669 [main] DEBUG org.hibernate.cfg.EJB3DTDEntityResolver:40 - located [file:///C:/dev/intellijprojects/hibernate-examples/orm_1_0.xsd] in classpath
2007-04-18 14:59:05,810 [main] INFO  org.hibernate.cfg.AnnotationConfiguration:163 - Mapping package example

The problem is caused by the order of the addResource and addPackage calls in combination with having a package-info.java file with some contents. If the addPackage is called before the addResource, or if the GenericGenerator annotation in the package info file is removed, there is no problem.

I cannot change the order of those calls for my production code, however, because Spring is being used to create the SessionFactory and it calls the methods in that order: resource followed by package.

There appears to be a problem with initializing
org.hibernate.cfg.annotations.reflection.EJB3OverridenAnnotationReader. When this call is made on line 360:
Code:
annotationsMap.put( ann.annotationType(), ann );
the map is null. Inserting a creation for the map, (borrowed form elsewhere in the method) on line 359, before the "for" statement:
Code:
annotationsMap = new HashMap<Class, Annotation>( annotations.length + 5 );
resolves the problem.

I wanted to post this here just to be sure there isn't something I could be missing before I create an issue in the JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 6:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Create the JIRA issue with the attached test case.
Thanks.

Out of curiosity, why an empty file?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Created a JIRA issue
PostPosted: Wed May 02, 2007 1:10 pm 
Newbie

Joined: Mon Apr 16, 2007 5:52 pm
Posts: 13
Number 608:

http://opensource.atlassian.com/project ... se/ANN-608

With regard to the orm.xml file being empty: I was just simplifying the test case. I have a table-generator defined in it in my production code.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.