• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Hibernate, but tables are not saved

 
Henrik Engert
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using Hibernate 3 with HSQLDB.

I have the following Java Bean:



Mapping file looks like this:



Hibernate configuration looks like this:



I then use a DAO to insert and retreive data. The insert seems to work since I do get back an id of the row inserterted into the PILOT table. But once I try to retrieve the inserted row I get the follwing error:

java.lang.Exception: PILOT is not mapped [from PILOT where id = :id]

It's like the tables are not created.

Can anybody help me?

Thanks.
[ February 06, 2007: Message edited by: Henrik Engert ]
 
Henrik Engert
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved the problem with this line:

Query q = getSession().createQuery("from Pilot where id = :id");

Changed from PILOT to Pilot.....

BUT, why does the data not persist in the database when I restart the application? If you start the app again with a SELECT (Query q = getSession().createQuery("from Pilot where id = :id") then the data is not there?!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are losing the database data because you are using Hypersonic and using it as an in-memory database, so as soon as you close it, the data goes bye-bye. Try using MySql as a database. Hypersonic is good for testing your app, but not really used for production, when you really want your data to be saved for the long haul.

Mark
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh, come on Mark. HSQLDB is great for development purposes. You just need to know how to kick it off correctly. I have an ant script for starting and stopping an HSQLDB server.



Now, since it starts in server mode, it will be persisted between startups. Here is my dataSource for development. I am using Spring, but you should get the general idea.



And yes, I am using Hibernate on this project and it works great. Of course, this database is quite volitile as I am using the schemaexport ant task to generate my DDL from my annotated classes.
 
Henrik Engert
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

I did suspect that I was running in memory only, but I thought as soon as I added the "file" in the hibernate.cfg.xml file that it would actually write the data to file.

I am new to all this with Hibernate. I really don't want to use MySQL for my ultra small application that I am trying do write. But I must say that MySQL is far easier to maintain.

I did get Hibernate to work with Derby instead.

Thanks again.
[ February 07, 2007: Message edited by: Henrik Engert ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't get me wrong Gregg, I use Hypersonic a lot for development, that is what I really meant when I said testing, I included development in my term, because I was using the term broadly and not the IT specific term.

Let me go answer your other thread.

Mark
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic