• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Collection Mapping

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am new to Hibernate. I am entangled with Collection-Mappping.I need some good tutorial having complete example program on Collection Mapping.

Also, i tried the following to test Collection mapping.

I wrote the following POJO class:


I wrote the following class to persist an object of type Book into the MYSQL database running on local host:




The following is the content of my mapping file:



When run the second program, i am getting the following output:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
null
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernatecollection.BookInsert.main(BookInsert.java:52)

The line where the NullPointerException took place corresponds to:

session.flush();

Kindly let me know where i could have gone wrong.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you are trying to flush a session that is null. So I would assume that something has gone wrong in these two lines:

What other exception messages do you have in your log? Has the SessionFactory been properly configured? Is the DataSource valid and can you connect to the database.
[ September 11, 2008: Message edited by: Paul Sturrock ]
 
author and cow tipper
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as finding tutorials on collection mapping, might I suggest my own?

I've got some very simple and straight forward examples on how to map one to one, one-to-many and many-to-many associations. Many people have found these tutorials very helpful.

Mapping Collections with Hibernate

-Cameron McKenzie
 
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic