This is my spring-master.xml
my spring-datasource.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:property-placeholder location="classpath*:META-INF/spring/*.properties" /> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> <!--Component, @Repository, and @Service --> <context:component-scan base-package="com.reglamb"> <!--avoid instantiating our @Controller classes --> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <context:exclude-filter expression="org.springframework.stereotype.Repository" type="annotation" /> </context:component-scan> <context:component-scan base-package="com.reglamb.projvehi" /> <import resource="spring-datasource.xml" /> <import resource="spring-hibernate.xml" /> </beans>
and my spring-hibernate.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"> <bean id="vehicDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}"/> </beans>
My Dao Class and Imp :Code:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- Hibernate SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" p:dataSource-ref="vehicDataSource" p:lobHandler-ref="defaultLobHandler"> <property name="annotatedClasses"> <list> <value>com.reglamb.projvehi.domain.Solicitante</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=${hibernate.dialect} hibernate.jdbc.batch_size=${hibernate.jdbc.batch_size} hibernate.c3p0.max_size=${hibernate.c3p0.max_size} hibernate.c3p0.min_size=${hibernate.c3p0.min_size} hibernate.c3p0.timeout=${hibernate.c3p0.timeout} hibernate.c3p0.max_statements=${hibernate.c3p0.max_statements} hibernate.c3p0.idle_test_period=${hibernate.c3p0.idle_test_period} hibernate.c3p0.acquire_increment=${hibernate.c3p0.acquire_increment} hibernate.c3p0.validate=${hibernate.c3p0.validate} <!--hibernate.cache.provider_class=${hibernate.cache.provider_class}--> hibernate.connection.provider_class=${hibernate.connection.provider_class} hibernate.show_sql=${hibernate.show_sql} hibernate.hbm2ddl.auto=update <!--hibernate.cache.use_second_level_cache=true--> <!--hibernate.cache.use_query_cache=true--> </value> </property> </bean> <!-- Database LOB Handling --> <bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler"/> <!-- Transaction Config --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory"/> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" p:sessionFactory-ref ="sessionFactory"/> <bean id="solicitanteDao" class="com.reglamb.projvehi.dao.hibernate.SolicitanteDaoHibernate" > <property name="hibernateTemplate" ref ="hibernateTemplate" /> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> </beans>
Code:import java.io.Serializable; import java.util.List; import com.reglamb.projvehi.domain.Solicitante; public interface SolicitanteDao extends GenericDao<Solicitante>,Serializable{ public void saveUser(Solicitante solicitante); public void deleteUser(String solicitante) ; public List<Solicitante> getAllUser(Solicitante solicitante) ; public Solicitante selectUserById(String solicId) ; }I want to probe this by Junit like this:Code:<!-----------------Impl------------------------------------------> @Repository("solicitanteDao") public class SolicitanteDaoHibernate extends HibernateDaoSupport implements SolicitanteDao{ private static final long serialVersionUID = 1L; //@Transactional(readOnly = false) //@Transactional public void saveUser(Solicitante solicitante) { getHibernateTemplate().saveOrUpdate(solicitante); } public void deleteUser(String solicitante) { getHibernateTemplate().delete(solicitante); } @SuppressWarnings("unchecked") //@Transactional public List<Solicitante> getAllUser(Solicitante solicitante) { return (List<Solicitante>) getHibernateTemplate().find("from " + Solicitante.class.getName()); } public Solicitante selectUserById(String solicId) { return getHibernateTemplate().get(Solicitante.class, solicId); }
Run this by Junit test and take this:Code:@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:/META-INF/spring/spring-master.xml"}) @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true) @Transactional() public class DataJUnitTest { @Autowired SolicitanteDao solicitanteDao; @Test public void testCreateData() { Solicitante solic = new Solicitante(); solic.setLastname("AYAMBO"); solic.setName("TOLEDO"); System.out.println("sOMETHING ???"); solicitanteDao.saveUser(solic); Assert.assertEquals(1, solicitanteDao.getAllUser(new Solicitante()).size()); } }
The database is create but the data id-generated,ayambo,toledo not inserted, the database is Postgresql 9.0.3, Pls?, What i do wrong???Code:Running com.reglamb.projvehi.test.DataJUnitTest SOMETHING ??? Hibernate: select nextval ('hibernate_sequence') Hibernate: insert into Solicitante (lastname, name, solicId) values (?, ?, ?) Hibernate: select solicitant0_.solicId as solicId0_, solicitant0_.lastname as lastname0_, solicitant0_.name as name0_ from Solicitante solicitant0_ Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.906 sec
Pdta: I now that hibernatetemplate is unused, but the configuration is ok??(Sorry for my bad english.)


Reply With Quote
