I removed the line with autocimmit. Tried to delete record from db.
My context now:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>org.postgresql.Driver</value>
</property>
<property name="url">
<value>jdbc:postgresql://${url}</value>
</property>
<property name="username">
<value>${user}</value>
</property>
<property name="password">
<value>${pass}</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>org.mbs.billing.model.Phase</value>
<value>org.mbs.billing.model.PhaseType</value>
<value>org.mbs.billing.model.RoadMap</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="phaseRepository"
class="org.mbs.billing.repository.impl.HibernatePhaseRepository">
<constructor-arg ref="sessionFactory" />
</bean>
<bean id="phaseTypeRepository"
class="org.mbs.billing.repository.impl.HibernatePhaseTypeRepository">
<constructor-arg ref="sessionFactory" />
</bean>
<bean id="roadMapRepository"
class="org.mbs.billing.repository.impl.HibernateRoadMapRepository">
<constructor-arg ref="sessionFactory" />
</bean>
</beans>
DAO:
Code:
package org.mbs.billing.repository.impl;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.mbs.billing.model.PhaseType;
import org.mbs.billing.repository.PhaseTypeRepository;
public class HibernatePhaseTypeRepository implements PhaseTypeRepository {
private SessionFactory sessionFactory;
public PhaseType getByID(int id) {
return (PhaseType) getCurrentSession().load(PhaseType.class,
Integer.valueOf(id));
}
public HibernatePhaseTypeRepository(SessionFactory sessionFactory) {
super();
this.sessionFactory = sessionFactory;
}
public PhaseType getByName(String name) {
return (PhaseType) getCurrentSession().createQuery(
"from phase_type where name = :name").setString("name", name)
.uniqueResult();
}
protected Session getCurrentSession() {
try {
return sessionFactory.getCurrentSession();
} catch (Exception e) {
return sessionFactory.openSession();
}
}
public void delete(int id) {
PhaseType phaseType = (PhaseType)getCurrentSession().load(PhaseType.class, id);
getCurrentSession().delete(phaseType);
}
public void store(PhaseType phaseType) {
getCurrentSession().saveOrUpdate(phaseType);
}
}
Executing code:
Code:
public static void main(String[] args) {
ApplicationContext ctx = new FileSystemXmlApplicationContext(
"C:\\springsource\\core-spring-workspace\\org.mbs.billing\\src\\main\\java\\org\\mbs\\billing\\context.xml");
PhaseTypeRepository rep = (PhaseTypeRepository) ctx
.getBean("phaseTypeRepository");
PhaseType pt = rep.getByID(1);
System.out.println(pt.toString());
rep.delete(1);
}
Console out:
Code:
log4j:WARN Continuable parsing error 42 and column 23
log4j:WARN The content of element type "log4j:configuration" must match "(renderer*,appender*,(category|logger)*,root?,categoryFactory?)".
INFO : org.springframework.context.support.FileSystemXmlApplicationContext - Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@cbf30e: display name [org.springframework.context.support.FileSystemXmlApplicationContext@cbf30e]; startup date [Mon Nov 01 00:25:26 EET 2010]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from file [C:\springsource\core-spring-workspace\org.mbs.billing\src\main\java\org\mbs\billing\context.xml]
INFO : org.springframework.context.support.FileSystemXmlApplicationContext - Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext@cbf30e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1884174
INFO : org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from file [C:\springsource\core-spring-workspace\org.mbs.billing\src\main\java\org\mbs\billing\datasource.properties]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1884174: defining beans [org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,dataSource,sessionFactory,transactionManager,phaseRepository,phaseTypeRepository,roadMapRepository]; root of factory hierarchy
Hibernate: select phasetype0_.ID as ID1_0_, phasetype0_.NAME as NAME1_0_ from mbs.PHASE_TYPE phasetype0_ where phasetype0_.ID=?
PhaseType [id=1, name=test]
Hibernate: select phasetype0_.ID as ID1_0_, phasetype0_.NAME as NAME1_0_ from mbs.PHASE_TYPE phasetype0_ where phasetype0_.ID=?
Would you be so kind to help me with this problem?