Hi, i'm trying to use for the first time hibernate for the java persistence, i've tryed to map one simple pojo, i've created some object and i saved it on my mysql database with the command save().
I have a problem: if i use the program in a second time, changing the data of the object, the old data is overwrite with the new, why?
thank you
p.s. sorry for the bad english, i'm italian :D
This is the code
Code:
public static void main(String args[]){
// Session session=HibernateUtil.getSessionFactory().getCurrentSession();
SessionFactory sessionFactory = new Configuration().configure() .buildSessionFactory();
Auto a=new Auto(4,"renault","19",1991);
Auto b=new Auto(5,"fiat","punto ",1999);
Auto c=new Auto(6,"fiat","barchetta ",2000);
ArrayList<Auto> au=new ArrayList<Auto>();
au.add(b);
au.add(a);
au.add(c);
Iterator<Auto> it;
it=au.iterator();
Session session;
while(it.hasNext()){
session =sessionFactory.openSession();
session.beginTransaction();
session.save(it.next());
//session.flush();
session.getTransaction().commit();
}