File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Setup

 
Drew Lane
Ranch Hand
Posts: 296
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
eammon bannon
Ranch Hand
Posts: 140
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ariel Araza
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic