-->
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.  [ 7 posts ] 
Author Message
 Post subject: Beginners Problem: NullPointerException @ getTypeFromXML
PostPosted: Tue Oct 19, 2004 6:24 am 
Newbie

Joined: Tue Oct 19, 2004 5:52 am
Posts: 5
Hi all -

I'm a plain old beginner in using hibernate and trying to write some mappings by hand - I've read the reference doc and "Hibernate in Action" - And to my dishonour, i'm still not able to define a simple one-to-many-collection-association between two tables :-|

The two mapping files below work without errors until i insert the <list> - Element in the Topic.hbm.xml - The insertion causes a thrown NullPointerException by Hibernate as can be seen in the stacktrace...

Anyone out there who can help me, please?

thanks in advance
and greets from Salzburg, Austria

jaro

General information:

I'm testing on resin, restarting the associated web-app every time i changed the mapping files, so that hibernate starts a new run.

Hibernate version: 2.1.6

Mapping documents:

Topic.hbm.xml

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
  PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping schema="NL" package="at.bmw.ids.newsletter">
  <class name="Topic" table="TOPIC">
    <!-- Identifiers -->
    <id name="id" type="long" unsaved-value="null">
      <column name="id" sql-type="NUMBER" not-null="true" />
        <generator class="sequence">
          <param name="sequence">TOPIC_SEQ</param>
        </generator>
      </id>
    <timestamp name="version" column="VERSION" />

    <!-- Relations -->
    [b]<list name="newsletters" inverse="true">
      <key column="TOPIC_ID" />
      <one-to-many class="Newsletter" />
    </list>[/b]

    <!-- Properties -->
    ...

  </class>
</hibernate-mapping>


Newsletter.hbm.xml

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
  PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping schema="NL" package="at.bmw.ids.newsletter">
  <class name="Newsletter" table="NEWSLETTER" lazy="true">
    <!-- Identifiers -->
    <id name="id" type="long" unsaved-value="null">
      <column name="id" sql-type="NUMBER" not-null="true" />
      <generator class="sequence">
        <param name="sequence">NEWSLETTER_SEQ</param>
      </generator>
     </id>

     <timestamp name="version" column="VERSION" />

     <!-- Relations -->

     <many-to-one name="parentTopic" column="TOPIC_ID" class="Topic" not-null="true" />

     <!-- Properties -->
     ...

  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

I'm not reaching the code since my mapping skills kill hibernate before.

Full stack trace of any exception that occurs:

Code:
java.lang.NullPointerException
  at net.sf.hibernate.cfg.Binder.getTypeFromXML(Binder.java:927)
  at net.sf.hibernate.cfg.Binder.bindSimpleValue(Binder.java:435)
  at net.sf.hibernate.cfg.Binder.bindListSecondPass(Binder.java:1108)
  at net.sf.hibernate.cfg.Binder$ListSecondPass.secondPass(Binder.java:1409)
  at net.sf.hibernate.cfg.Binder$SecondPass.doSecondPass(Binder.java:1355)
  at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:632)
  at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:784)
  at at.bmw.ids.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:15)
  at _jsp._testing._hibernatetest__jsp._jspService(/testing/HibernateTest.jsp:22)
  at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
  at com.caucho.jsp.Page.pageservice(Page.java:571)
  at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:155)
  at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:211)
  at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
  at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
  at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
  at com.caucho.server.port.TcpConnection.run(TcpConnection.java:331)
  at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:464)
  at com.caucho.util.ThreadPool.run(ThreadPool.java:408)
  at java.lang.Thread.run(Thread.java:534)


Name and version of the database you are using:

Oracle 9.x

The generated SQL (show_sql=true):

No SQL were created since Hibernate ended before that with an Exception

Debug level Hibernate log excerpt:


INFO thread-pool-13 net.sf.hibernate.cfg.Environment - Hibernate 2.1.6
INFO thread-pool-13 net.sf.hibernate.cfg.Environment - hibernate.properties not found
INFO thread-pool-13 net.sf.hibernate.cfg.Environment - using CGLIB reflection optimizer
INFO thread-pool-13 net.sf.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
INFO thread-pool-13 net.sf.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
DEBUG thread-pool-13 net.sf.hibernate.util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath under net/sf/hibernate/
DEBUG thread-pool-13 net.sf.hibernate.util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath
DEBUG thread-pool-13 net.sf.hibernate.cfg.Configuration - connection.datasource=java:comp/env/jdbc/nl
DEBUG thread-pool-13 net.sf.hibernate.cfg.Configuration - show_sql=true
DEBUG thread-pool-13 net.sf.hibernate.cfg.Configuration - dialect=net.sf.hibernate.dialect.Oracle9Dialect
DEBUG thread-pool-13 net.sf.hibernate.cfg.Configuration - null<-org.dom4j.tree.DefaultAttribute@1a70b8 [Attribute: name resource value "at/bmw/ids/newsletter/Topic.hbm.xml"]
INFO thread-pool-13 net.sf.hibernate.cfg.Configuration - Mapping resource: at/bmw/ids/newsletter/Topic.hbm.xml
DEBUG thread-pool-13 net.sf.hibernate.util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
DEBUG thread-pool-13 net.sf.hibernate.util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
INFO thread-pool-13 net.sf.hibernate.cfg.Binder - Mapping class: at.bmw.ids.newsletter.Topic -> TOPIC
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: id -> id, type: long
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: version -> VERSION, type: timestamp
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: newsletters, type: java.util.List
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: name -> NAME, type: string
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: description -> DESCRIPTION, type: string
DEBUG thread-pool-13 net.sf.hibernate.cfg.Configuration - null<-org.dom4j.tree.DefaultAttribute@83d8be [Attribute: name resource value "at/bmw/ids/newsletter/Newsletter.hbm.xml"]
INFO thread-pool-13 net.sf.hibernate.cfg.Configuration - Mapping resource: at/bmw/ids/newsletter/Newsletter.hbm.xml
DEBUG thread-pool-13 net.sf.hibernate.util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
DEBUG thread-pool-13 net.sf.hibernate.util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
INFO thread-pool-13 net.sf.hibernate.cfg.Binder - Mapping class: at.bmw.ids.newsletter.Newsletter -> NEWSLETTER
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: id -> id, type: long
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: version -> VERSION, type: timestamp
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: parentTopic -> TOPIC_ID, type: at.bmw.ids.newsletter.Topic
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: title1 -> TITLE1, type: string
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: title2 -> TITLE2, type: string
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: text -> TEXT, type: string
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: sortorder -> SORTORDER, type: long
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: sentFrom -> SENT_FROM, type: long
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: dateSent -> DATE_SENT, type: timestamp
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: dateCreated -> DATE_CREATED, type: timestamp
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Mapped property: dateLastmodified -> DATE_LASTMODIFIED, type: timestamp
INFO thread-pool-13 net.sf.hibernate.cfg.Configuration - Configured SessionFactory: null
DEBUG thread-pool-13 net.sf.hibernate.cfg.Configuration - properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, sun.boot.library.path=C:\Programme\j2sdk1.4.2_05\jre\bin, java.vm.version=1.4.2_05-b04, javax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl, connection.datasource=java:comp/env/jdbc/nl, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=AT, sun.os.patch.level=, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\Programme\resin-3.0.8, org.xml.sax.driver=com.caucho.xml.Xml, java.runtime.version=1.4.2_05-b04, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Programme\j2sdk1.4.2_05\jre\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\3\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, java.util.logging.manager=com.caucho.log.LogManagerImpl, java.naming.factory.url.pkgs=com.caucho.naming, os.name=Windows 2003, resin.home=C:\Programme\resin-3.0.8, sun.java2d.fontpath=, log4j.configuration=c:\programme\resin-3.0.8\lib\log4j.conf, hibernate.connection.datasource=java:comp/env/jdbc/nl, java.library.path=C:\Programme\j2sdk1.4.2_05\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Programme\j2sdk1.4.2_05\bin;;C:\Programme\resin-3.0.8\bin;\Program Files\GnuWin32\bin, java.specification.name=Java Platform API Specification, java.class.version=48.0, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, os.version=5.2, user.home=C:\Dokumente und Einstellungen\Administrator, user.timezone=Europe/Berlin, javax.rmi.CORBA.PortableRemoteObjectClass=weblogic.iiop.PortableRemoteObjectDelegateImpl, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.4, show_sql=true, java.class.path=C:\Programme\resin-3.0.8\classes;C:\Programme\resin-3.0.8\lib\resin.jar;C:\Programme\j2sdk1.4.2_05\lib\tools.jar;C:\Programme\j2sdk1.4.2_05\jre\lib\rt.jar;C:\Programme\resin-3.0.8\lib\dom.jar;C:\Programme\resin-3.0.8\lib\grops-authenticator.jar;C:\Programme\resin-3.0.8\lib\grops-bean-interfaces.jar;C:\Programme\resin-3.0.8\lib\isorelax.jar;C:\Programme\resin-3.0.8\lib\jca-15.jar;C:\Programme\resin-3.0.8\lib\jmx-12.jar;C:\Programme\resin-3.0.8\lib\jsdk-24.jar;C:\Programme\resin-3.0.8\lib\jstl-11.jar;C:\Programme\resin-3.0.8\lib\jta-101.jar;C:\Programme\resin-3.0.8\lib\license.jar;C:\Programme\resin-3.0.8\lib\log4j-1.2.8.jar;C:\Programme\resin-3.0.8\lib\portlet-10.jar;C:\Programme\resin-3.0.8\lib\weblogic.jar;C:\Programme\resin-3.0.8\lib\webutil.jar, user.name=Administrator, hibernate.show_sql=true, java.naming.factory.initial=com.caucho.naming.InitialContextFactoryImpl, java.vm.specification.version=1.0, java.home=C:\Programme\j2sdk1.4.2_05\jre, sun.arch.data.model=32, hibernate.dialect=net.sf.hibernate.dialect.Oracle9Dialect, user.language=de, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, java.version=1.4.2_05, java.ext.dirs=C:\Programme\j2sdk1.4.2_05\jre\lib\ext, sun.boot.class.path=C:\Programme\j2sdk1.4.2_05\jre\lib\rt.jar;C:\Programme\j2sdk1.4.2_05\jre\lib\i18n.jar;C:\Programme\j2sdk1.4.2_05\jre\lib\sunrsasign.jar;C:\Programme\j2sdk1.4.2_05\jre\lib\jsse.jar;C:\Programme\j2sdk1.4.2_05\jre\lib\jce.jar;C:\Programme\j2sdk1.4.2_05\jre\lib\charsets.jar;C:\Programme\j2sdk1.4.2_05\jre\classes, java.vendor=Sun Microsystems Inc., file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, dialect=net.sf.hibernate.dialect.Oracle9Dialect, sun.cpu.isalist=pentium i486 i386}
INFO thread-pool-13 net.sf.hibernate.cfg.Configuration - processing one-to-many association mappings
DEBUG thread-pool-13 net.sf.hibernate.cfg.Binder - Second pass for collection: at.bmw.ids.newsletter.Topic.newsletters
INFO thread-pool-13 net.sf.hibernate.cfg.Binder - Mapping collection: at.bmw.ids.newsletter.Topic.newsletters -> NEWSLETTER


Top
 Profile  
 
 Post subject: Workaround?
PostPosted: Tue Oct 19, 2004 7:19 am 
Newbie

Joined: Tue Oct 19, 2004 5:52 am
Posts: 5
Hi all -

The error doesn't occur if i use a java.util.Set instead of the java.util.List in the java-class and the <set>-Element instead of the <list>-Element in the mapping file?

I don't quite understand the difference except that a list can be ordered by providing a <index>-Element and can hold duplicate entries?

anyone a clue?

thanks in advance,

jaro


Top
 Profile  
 
 Post subject: Solved
PostPosted: Thu Oct 21, 2004 3:44 am 
Newbie

Joined: Tue Oct 19, 2004 5:52 am
Posts: 5
If anyone is interested though -

I forgot the table attribute in the <list> element - So hibernate threw the exception. This error can't be found anywhere and for beginners in orm, the reference documentation imo is crap (sorry i have to write that word).

Wouldn't this be the first point to start to easely get more users?

So:

In Richard Burns Rally they say: "If you have to many accidents, you drive to fast". Me says: "If you have to many Exceptions while decrypting the reference manual, read Hibernate in action". This book is a real enlightment - Thanks Christian and Gavin.

jaro


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 3:46 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Don't forget to post your review to our Amazon page ;)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Urg
PostPosted: Thu Oct 21, 2004 9:07 am 
Newbie

Joined: Tue Oct 19, 2004 5:52 am
Posts: 5
Done finishing my review on amazon, sent it - And hadn't rated actually.
Since i can't find a way to change the rating (i can change the text) after sending it, it's stuck to one puny point... But i hope the text corrects that somehow.

"Never ask a stranger to rate the own book - he might do something catastrophically wrong"

an ashamed sorry from Salzburg,

jaro


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 24, 2004 10:31 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
Jaro,
?
Why not use an xml editor that will catch all these problems via the DTD?

J


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 03, 2004 8:16 am 
Newbie

Joined: Tue Oct 19, 2004 5:52 am
Posts: 5
Quote:
Why not use an xml editor that will catch all these problems via the DTD?


I'm already using an editor (idea) which supports validation of written xml by using the hibernate dtd.

But there is no error saying "You have to use the table attribute when using a <index> Tag. It usually tells you "You have written a nonexistant tag or attribute in this context".

So forgetting the table-attribute in the <list> tag wasn't a problem for the validator since everything else was well-formed and correct.

Jaro[/quote]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.