Does your Person.java use a String instead of a Long for its id?

On Tue, Mar 30, 2010 at 8:21 AM, markthien <[email protected]> wrote:

>
> Hi Matt,
>
> I tried changing to:
>
>    @Autowired
>    public void setPersonDao(GenericDao<Person, Long> personDao) {
>        this.personDao = personDao;
>    }
>
> and run "mvn test -Dtest=PersonDaoTest -Dsurefire.useFile=false" then I got
> the following error:
>
> [INFO] [compiler:testCompile {execution: default-testCompile}]
> [INFO] Compiling 1 source file to
> C:\workspace\myproject\target\test-classes
> [INFO]
> ------------------------------------------------------------------------
> [ERROR] BUILD FAILURE
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Compilation failure
>
> C:\workspace\myproject\src\test\java\org\appfuse\dao\PersonDaoTest.java:[18,25]
> incompatible types
> found   :
> org.appfuse.dao.GenericDao<org.appfuse.model.Person,java.lang.Long>
> required: org.appfuse.dao.PersonDao
>
> my PersonDaoTest.class is below:
>
> package org.appfuse.dao;
>
> import java.util.List;
>
> import org.appfuse.model.Person;
> import org.junit.Test;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.test.annotation.ExpectedException;
> import org.springframework.dao.DataAccessException;
> import static org.junit.Assert.*;
>
> public class PersonDaoTest extends BaseDaoTestCase {
>    @Autowired
>    private PersonDao personDao;
>
>    @Autowired
>    public void setPersonDao(GenericDao<Person, Long> personDao) {
>        this.personDao = personDao;
>    }
>
>     @Test
>    public void testFindPersonByLastName() throws Exception {
>        List<Person> people = personDao.findByLastName("Raible");
>        assertTrue(people.size() > 0);
>    }
>
>    @Test
>    public void testFindPersonByFullName() throws Exception {
>        List<Person> people = personDao.findByFullName("Raible","Matt");
>        assertTrue(people.size() > 0);
>    }
>
>    @Test
>    @ExpectedException(DataAccessException.class)
>    public void testAddAndRemovePerson() throws Exception {
>        Person person = new Person();
>        person.setFirstName("Country");
>        person.setLastName("Bry");
>
>        person = personDao.save(person);
>        flush();
>
>        person = personDao.get(person.getId());
>
>        assertEquals("Country", person.getFirstName());
>        assertNotNull(person.getId());
>
>        log.debug("removing person...");
>
>        personDao.remove(person.getId());
>        flush();
>
>        // should throw DataAccessException
>        personDao.get(person.getId());
>    }
>
>
> }
>
> and the applicationContext-dao.xml is below
>
>
> <?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:context="http://www.springframework.org/schema/context";
>       xsi:schemaLocation="http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>            http://www.springframework.org/schema/context
> http://www.springframework.org/schema/context/spring-context-2.5.xsd";
>       default-lazy-init="true">
>
>    <bean
>
> class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
>
>    <!-- Hibernate SessionFactory -->
>    <bean id="sessionFactory"
>
> class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
>        <property name="dataSource" ref="dataSource"/>
>        <property name="configLocation"
> value="classpath:hibernate.cfg.xml"/>
>        <property name="hibernateProperties">
>            <value>
>                hibernate.dialect=${hibernate.dialect}
>                hibernate.query.substitutions=true 'Y', false 'N'
>                hibernate.cache.use_second_level_cache=true
>
> hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
>            </value>
>            <!-- Turn batching off for better error messages under
> PostgreSQL -->
>            <!-- hibernate.jdbc.batch_size=0 -->
>        </property>
>    </bean>
>
>    <!-- Transaction manager for a single Hibernate SessionFactory
> (alternative to JTA) -->
>    <bean id="transactionManager"
> class="org.springframework.orm.hibernate3.HibernateTransactionManager">
>        <property name="sessionFactory" ref="sessionFactory"/>
>    </bean>
>
>    <!-- Activates scanning of @Autowired -->
>    <context:annotation-config/>
>
>    <!-- Activates scanning of @Repository -->
>    <context:component-scan base-package="org.appfuse.dao"/>
>
>    <!-- Compass Search Section -->
>
>    <!-- Compass Bean, automatically scanning for searchable classes within
> the model -->
>    <!-- Hooks into Spring transaction management and stores the index on
> the file system -->
>    <bean id="compass" class="org.compass.spring.LocalCompassBean">
>        <property name="mappingScan" value="org.appfuse.model" />
>        <property name="transactionManager" ref="transactionManager" />
>        <property name="settings">
>            <map>
>                <entry key="compass.engine.connection"
> value="target/test-index" />
>            </map>
>        </property>
>    </bean>
>
>    <!-- Compass Template allowing to automatically join/start exising
> transactions when performing operations -->
>    <bean id="compassTemplate" class="org.compass.core.CompassTemplate">
>        <property name="compass" ref="compass" />
>    </bean>
>
>    <!-- Compass Search Helper allowing to perform search operations in a
> simpler manner -->
>    <bean id="compassSearchHelper"
> class="org.compass.core.support.search.CompassSearchHelper">
>        <constructor-arg ref="compass" />
>        <property name="pageSize" value="10" />
>    </bean>
>
>    <!-- CompassGps will automatically mirror any changes done thorugh
> Hibernate to searchable classes to the index -->
>    <!-- It will also provide the index operation allowing to reindex the
> database -->
>    <bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps"
> init-method="start" destroy-method="stop">
>        <property name="compass" ref="compass" />
>        <property name="gpsDevices">
>            <list>
>                <bean
> class="org.compass.gps.device.hibernate.HibernateGpsDevice">
>                    <property name="name" value="hibernate" />
>                    <property name="sessionFactory" ref="sessionFactory" />
>                </bean>
>            </list>
>        </property>
>    </bean>
>
>    <bean class="org.appfuse.dao.spring.HibernateExtensionPostProcessor">
>        <property name="annotatedClasses">
>            <list>
>                <value>org.appfuse.model.Person</value>
>            </list>
>        </property>
>    </bean>
>
> </beans>
>
>
> PersonDao.class
>
>
> package org.appfuse.dao;
>
> import java.util.List;
>
> import org.appfuse.model.Person;
>
> public interface PersonDao extends GenericDao<Person, Long> {
>    public List<Person> findByLastName(String lastName);
>
>    public List<Person> findByFullName(String lastName, String firstName);
> }
>
>
> PersonDaoHibernate.class:
>
>
> package org.appfuse.dao.hibernate;
>
> import java.util.List;
>
> import org.appfuse.dao.PersonDao;
> import org.appfuse.model.Person;
> import org.springframework.stereotype.Repository;
>
> @Repository("personDao")
> public class PersonDaoHibernate extends GenericDaoHibernate<Person, Long>
> implements PersonDao {
>
>    public PersonDaoHibernate() {
>        super(Person.class);
>    }
>
>    @SuppressWarnings("unchecked")
>    public List<Person> findByLastName(String lastName) {
>        return getHibernateTemplate().find("from Person where lastName=?",
> lastName);
>    }
>
>    @SuppressWarnings("unchecked")
>    public List<Person> findByFullName(String lastName, String firstName) {
>        return getHibernateTemplate().find("from Person where lastName=? and
> firstName=?", new String[]{lastName, firstName});
>    }
> }
>
>
> I have not been using Spring and Hibernate for almost 3 years due to the
> company that I working with using their own freaking framework. %-|
>
> Cheers,
> Mark Thien
> --
> View this message in context:
> http://n4.nabble.com/No-need-to-register-personDao-in-applicationContext-dao-xml-anymore-tp1744994p1745281.html
> Sent from the AppFuse - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to