jQuery in Action, 3rd edition
The moose likes Object Relational Mapping and the fly likes Session throwing NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Session throwing NullPointerException" Watch "Session throwing NullPointerException" New topic

Session throwing NullPointerException

subhashchandra medhiassam
Ranch Hand

Joined: Sep 10, 2008
Posts: 72
Hi all,
I have a table named User in MYSQL database. Its columns are id(int),username(varchar) and activated(boolean). Corresponding to this table i have a class User.java.

Class User looks like the following:

I have another class FilterTest.java

It looks like the following:

I have my mapping files which look like the following:


and filters.hbm.xml:

When i run FilterTest.java, I am getting a NullPointerException corresponding to the "session.flush();" inside the finally block.

Could anybody kindly let me know what is causing this exception?

subhashchandra medhiassam
Ranch Hand

Joined: Sep 10, 2008
Posts: 72
Now, I changed the file filters.hbm.xml. I brought the portion
to the top so that the file now looks like the following:

Now, when i run FilterTest.java, i am getting the following message:

org.hibernate.MappingException: Error reading resource: filters.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:447)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1381)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1335)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1302)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at FilterTest.main(FilterTest.java:22)
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:394)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
... 7 more
Caused by: org.xml.sax.SAXParseException: The content of element type "hibernate-mapping" must match "(meta*,typedef*,import*,(class|subclass|joined-subclass)*,(query|sql-query)*,filter-def*)".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:393)
... 8 more
Exception in thread "main" java.lang.NullPointerException
at FilterTest.main(FilterTest.java:48)

Could anybody please help me find out the cause and remedy the problem?

subhashchandra medhiassam
Ranch Hand

Joined: Sep 10, 2008
Posts: 72
My problem is solved. I had added some extra jars,asm-3.1.jar and asm-attrs.jar. When i removed them the issue got solved. Could anybody tell me why these jars were causing the problem?

I agree. Here's the link: http://aspose.com/file-tools
subject: Session throwing NullPointerException
It's not a secret anymore!