1 Reply Latest reply on Sep 14, 2010 3:08 AM by lvdberg

    Keep Database Changes after server shutdown?

    sado
      I'm new to Seam. I have an entity bean setup and it properly creates a table upon application start, and adds rows to the table as i create instances of the class. The problem is the table and rows all dissapear when I shut down my JBoss server. Is there something wrong with how I am doing things?

      The bean is setup with these annotations:
      @Entity
      @Name("user")
      @Scope(SESSION)
      @Table(name="users")


      I get the EntityManager this way:
         @PersistenceContext
         private EntityManager em;


      And, after I verify that the user does not already exist in the database, I call:
               em.persist(user);



      Hmm. Not sure where to look. Is the @Scope(SESSION) the problem?
        • 1. Re: Keep Database Changes after server shutdown?
          lvdberg

          Hi,


          this is a setting in the file persistence.xml. This file contains all properties to map the objects to the DB and it contains additional settings for Hibernate.


          Look for the following line in that file:




          <property name="hibernate.hbm2ddl.auto" value="create-drop" />





          and change it to:




          <property name="hibernate.hbm2ddl.auto" value="update" />



          This will keep the DB after shutdown and makes the neceesary changes in the DB while you're developing. Keep in mind that for developing purposes this works fine, but for production it needs the help of a professional DB-administrator to get the fine-tuning right.


          Leo