-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate clears table in mysql database?!
PostPosted: Tue Jun 06, 2006 11:23 am 
Newbie

Joined: Tue Jun 06, 2006 11:13 am
Posts: 2
Hi, I have a very very strange problem, which I cannot almost beleive myself but it looks like hibernate is clearing out my table!
I have a table which I insert a row to, and then verify the row by a ordinary select to the table. Ok everything ok.
Then I startup my .war application and suddenly the table is empty!

Here are some info:
Database: Mysql (latest version)
Tomcat 5.5.17
IDE: Eclipse WTP 3.1.2
Hibernate: 3.1.3

Session creation:
private static final SessionFactory sessionFactory;
sessionFactory = new Configuration().configure().buildSessionFactory();

Hibernate-mapping default.

CustomerFactory object:
Session session = HibernateSessionFactory.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query query = session.createQuery("select x from Customer as x WHERE x.id = :cid");
query = query.setParameter("cid", 1);
Customer customer =
(Customer)query.uniqueResult();
session.getTransaction().commit();
log.debug("Customer: " + customer);
(customer object always null)


Does anyone have a clue what I have messed up?


Top
 Profile  
 
 Post subject: Re: Hibernate clears table in mysql database?!
PostPosted: Tue Jun 06, 2006 2:34 pm 
Beginner
Beginner

Joined: Sat Jun 03, 2006 6:23 pm
Posts: 28
HibernateMe wrote:
Hibernate-mapping default.


The default hibernate.properties file (I assume that's what you refer to, there is no default mapping for classes I guess) contain entries for schema export, like these:

Code:
## auto schema export

#hibernate.hbm2ddl.auto create-drop
#hibernate.hbm2ddl.auto create
#hibernate.hbm2ddl.auto update
hibernate.hbm2ddl.auto validate

I'd make sure that your shema is not regenerated by Hibernate upon startup. This is useful for testing, but it might be the cause of confusion in your case. The value 'validate' only checks that the mappings you defined match the database to some degree, so maybe you want that.
The generated log should also be able to help you verify this.

Roland


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 4:10 pm 
Newbie

Joined: Tue Jun 06, 2006 11:13 am
Posts: 2
You were absolute right there, thank you and sorry for my blindness!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.