-->
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.  [ 5 posts ] 
Author Message
 Post subject: Newbie question - hibernate overwrites entities
PostPosted: Wed Sep 02, 2009 6:35 pm 
Newbie

Joined: Thu Aug 27, 2009 2:12 pm
Posts: 7
I have a sample controller that inserts my objects and it works perfectly. Only problem is that when it creates the entries the first time, it appears that it only updates them the next time and does not actually create new entries. Every time I run my app, I would expect to see a new row - instead I see the same row over and over. My ID is annotated to auto generate, but no such luck...

Code:

Code:
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
              Transaction transaction = session.beginTransaction();
      
              AuditEvent ae = new AuditEvent("SUCCES", "Launching web app");

              session.save(ae);      
      


model

Code:
@Entity
@Table(name = "Auditing")
public class AuditEvent implements Serializable {
   
    /**
    *
    */
   private static final long serialVersionUID = 1L;

   @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id = null;

    @Column(name = "status")
    private String status;

    @Column(name = "description")
    private String description;


Just in case, connection settings:

Code:
      AnnotationConfiguration config = new AnnotationConfiguration();
            config.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
            config.setProperty("hibernate.connection.driver_class", "net.sourceforge.jtds.jdbc.Driver");
            config.setProperty("hibernate.connection.url", "jdbc:jtds:sqlserver://localhost:3356/dev");
            config.setProperty("hibernate.connection.username", "ami");
            config.setProperty("hibernate.connection.password", "ami123");
            config.setProperty("hibernate.connection.pool_size", "1");
            config.setProperty("hibernate.connection.autocommit", "true");
            config.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");
            config.setProperty("hibernate.hbm2ddl.auto", "create-drop");
            config.setProperty("hibernate.show_sql", "true");
            config.setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");
            config.setProperty("hibernate.current_session_context_class", "thread");


Top
 Profile  
 
 Post subject: Re: Newbie question - hibernate overwrites entities
PostPosted: Wed Sep 02, 2009 7:06 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
When you 'run your app', do you stop and start the JVM on which it is running? I'm wondering if a static session might be hanging around. On first glance, it appears it should work.

Your session is closed and transaction committed at some point, right?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Newbie question - hibernate overwrites entities
PostPosted: Thu Sep 03, 2009 11:50 am 
Newbie

Joined: Thu Aug 27, 2009 2:12 pm
Posts: 7
Yes, I stop the tomcat server - restart and instead of creating a new entry it simply overwrites it...or I guess in this case, updates it.

This seems like really basic stuff...


Top
 Profile  
 
 Post subject: found the solution
PostPosted: Thu Sep 03, 2009 5:39 pm 
Newbie

Joined: Thu Aug 27, 2009 2:12 pm
Posts: 7
OK, the solution was to change hibernate.hbm2ddl.auto to 'update'.


Top
 Profile  
 
 Post subject: Re: Newbie question - hibernate overwrites entities
PostPosted: Fri Sep 04, 2009 12:27 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Oh no, you weren't recreating the database each time, were you! That's a tough problem to troubleshoot. :(

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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