• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Setup

 
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to setup and test Hibernate for the first time.
I used the quickstart as the basis of my experiment but now I'm stuck
when I try to run my servlet:

I'm sure it's just something I've configured incorrectly, but I'm not sure what it is.
I've setup my database, my database connection <resource-ref>, hibernate.cfg.xml, a class called "Petition", and Petition.hbm.xml as well as the HibernateUtil, and a simple servlet. I can post these if necessary.
Any suggestions would be appreciated.
Regards,
Drew
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are using hibernate.cfg.xml to define the mappings for your SessionFactory - so it would most useful if you could prost the directory structure you deploy into, particularaly where Petition.hbm.xml is.
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Turned out I had neglected to add the primary key to the mapping.
So, now it seems to be working. At least it's inserting data into the database now.
Whew! Seems like a lot of work setting this thing up.
Maybe this it totally naive, but will there ever come a time when you won't have to set up mappings?
Like the thing reads your database schema and creates something for you?
Drew
[ March 24, 2004: Message edited by: Drew Lane ]
 
eammon bannon
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are tools associated with Hibernate that claim to do this - Middlegen, Hibernate Synchronizer, XDoclet (very useful - all but eliminates mapping errors), class2hbm, hbm2java, ddl2hbm and hbm2ddl. Some better than others no doubt. Have a dig around on Hibernate's site - they are all there.
But don't worry, we've all been there! Just wait till you have to map a four-part composite key by hand for the first time...
[ March 24, 2004: Message edited by: eammon bannon ]
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, seems like it should be possible to create a mapping file from the class file fairly easily. I'll take a look at that.
BTW, one problem I'm having now is that I have to restart the server (Resin) whenever I change the map file. Otherwise it reads the original map file. This is not good.
How can I avoid this? Is there someone to force Hibernate to re-read this? Maybe turn some cache off?
Drew
 
eammon bannon
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry - don't know anything about Resin, but it sort of makes sense - the SessionFactory is a static configuration, its loaded once and never refreshed. I might be wrong about that - ask in the Hibernate.org forums, they are very quick to respond, and you usually get one of the developers.
What we do is configure the SessionFactory programatically, by adding classes to a Configuration - this way when we redeploy the app, the app server (JBoss) re-maps the Hibernate classes. You might want to try this if its not possible another way.
[ March 24, 2004: Message edited by: eammon bannon ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Drew Lane:
Turned out I had neglected to add the primary key to the mapping.
So, now it seems to be working. At least it's inserting data into the database now.
Whew! Seems like a lot of work setting this thing up.
Maybe this it totally naive, but will there ever come a time when you won't have to set up mappings?
Like the thing reads your database schema and creates something for you?
You might want to try Middlegen to do the above, the advantage to this over the built-in tools that Hibernate provides with its package is that it also generates XDoclet meta-data in your hbm.xml which becomes XDoclet tags in the generated Java code. These tags allow you to fine-tune the generated Java codes and generate back the hbm.xml.

Drew
[ March 24, 2004: Message edited by: Drew Lane ]

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic