-->
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: Deleting Current Data on Startup ??
PostPosted: Mon Nov 02, 2009 6:42 am 
Newbie

Joined: Mon Nov 02, 2009 6:14 am
Posts: 2
Hi All,

Hibernate newbie here, I've set up a Spring-MVC web app and plan to use hibernate as well. I've sort of have it all working. The application starts and I can add things into the database and fetch them, however when I start the application hibernate deletes all the current data on that database ??

Also if I try to find a page that doesn't exist in the database I get an java.lang.IndexOutOfBoundsException. Now I would have expected just a null value object, is this correct ??

I'm using hibernates HibernateDaoSupport to fetch and update data...

Code:
public class RankDaoImpl extends HibernateDaoSupport implements RankDao {

   @Override
   public RankVO findRankByPage(String page) {
      List<RankVO> list = getHibernateTemplate().find("from RankVO where id=?", page);
        return list.get(0);
   }

   @Override
   public List<PageVO> getAllRankVOs() {
       return getHibernateTemplate().loadAll(RankVO.class);
   }

      etc for update, remove, insert...


Code:

   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource">
         <ref bean="dataSource" />
      </property>
      <property name="configLocation">
         <value>WEB-INF/hibernate.cfg.xml</value>
      </property>
      <property  name="configurationClass">
            <value>org.hibernate.cfg.AnnotationConfiguration</value>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
            <prop key="hibernate.hbm2ddl.auto">create</prop>
         </props>
      </property>
   </bean>

   <bean id="txAttributeSource" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
      <property name="properties">
         <props>
            <prop key="add*">PROPAGATION_REQUIRED</prop>
            <prop key="update*">PROPAGATION_REQUIRED</prop>
            <prop key="remove*">PROPAGATION_REQUIRED</prop>
            <prop key="send*">PROPAGATION_REQUIRED</prop>
         </props>
      </property>
   </bean>

   <bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
      <property name="transactionManager">
         <ref local="transactionManager" />
      </property>
      <property name="transactionAttributeSource">
         <ref local="txAttributeSource" />
      </property>
   </bean>

   <bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
      <property name="transactionManager">
         <ref bean="transactionManager" />
      </property>
      <property name="transactionAttributes">
         <props>
            <prop key="save*">PROPAGATION_REQUIRED</prop>
            <prop key="add*">PROPAGATION_REQUIRED</prop>
            <prop key="remove*">PROPAGATION_REQUIRED</prop>
         </props>
      </property>
   </bean>

        With extra bean for the DAO etc...


Any help would be vastly appreciated !

Thanks


Top
 Profile  
 
 Post subject: Re: Deleting Current Data on Startup ??
PostPosted: Mon Nov 02, 2009 2:16 pm 
Newbie

Joined: Mon Nov 02, 2009 6:14 am
Posts: 2
Solved this...

The property

<prop key="hibernate.hbm2ddl.auto">create</prop>

just needed to be change to

<prop key="hibernate.hbm2ddl.auto">update</prop>

Hibernate was recreating the tables at startup hence the data disappeared


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.