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