-->
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.  [ 2 posts ] 
Author Message
 Post subject: problem writing data to the database
PostPosted: Tue Sep 07, 2004 9:33 am 
Newbie

Joined: Thu Sep 02, 2004 8:33 am
Posts: 6
Hello,

I am new to hibernate so maybe it is a stupid question.
I have made a simple application:
public static void main ( String[] args )throws HibernateException
{
Configuration cfg = new Configuration();
cfg.addClass(ch2.Message.class);

SessionFactory sf = cfg.buildSessionFactory();
Session session = sf.openSession();
Transaction tx = null;

try{
tx = session.beginTransaction();
Message message = new Message("Hello World");
Message nMes = new Message("hibernate");

session.save(message);
session.save(nMes);
tx.commit();
} catch (HibernateException e) {
if (tx!=null)
tx.rollback();
throw e;
}
finally {

session.close();
}
}

Everything is working fine he's writing the messages to the database.
Only i have a problem when i'm running the application again i want to right the same values again to the database. So i have 4 messages in the database:

1 -- Hello World
2 -- hibernate
3 -- Hello World
4 -- hibernate

but it looks like he overwrite the values in the database so the result is everytime:

1 -- Hello World
2 -- hibernate

anybody a suggestion?

Bart


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 10:19 am 
Regular
Regular

Joined: Wed May 05, 2004 8:01 am
Posts: 53
what is your primary key definition?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.