Classe Abstrata, DAO´s

Olá, eu montei uma classe abstrata para hibernate, como segue:

public abstract class AbstractHibernateDAO
{
	/** Object to access log4j */
	public static Logger log = Logger.getLogger(AbstractHibernateDAO.class);

	/** DataSource attribute */
	protected DataSource dataSource = null;
	
	/**
	 * Protected Constructor
	 * 
	 * @param factory
	 */
	protected AbstractHibernateDAO(SessionFactory factory)
	{
		dataSource = new DataSource();
		dataSource.setFactory(factory);
	}
	
	/**
	 * Creates the object
	 * 
	 * @param object
	 * @throws DAOException
	 */	
	public void create(Object object) throws DAOException
	{
		try
		{
			dataSource.insert(object);
		}
		catch (Exception e)
		{
			log.error("Method create: " + e);
			throw new DAOException(e.getMessage());
		}		
	}

	/**
	 * Updates the object
	 * 
	 * @param object
	 * 
	 * @throws DAOException
	 */	
	public void update(Object object) throws DAOException
	{
		try
		{
			dataSource.update(object);
		}
		catch (Exception e)
		{
			log.error("Method update: " + e);
			throw new DAOException(e.getMessage());
		}		
	}

	/**
	 * Deletes the object
	 * 
	 * @param object
	 * 
	 * @throws DAOException
	 */	
	public void delete(Object object) throws DAOException
	{
		try
		{
			dataSource.delete(object);
		}
		catch (Exception e)
		{
			log.error("Method delete: " + e);
			throw new DAOException(e.getMessage());
		}		
	}

	/**
	 * Loads the object
	 * 
	 * @param object
	 * 
	 * @return object
	 * 
	 * @throws DAOException
	 */	
	public Object load(Object object) throws DAOException
	{
		Object ret = null;
		Integer integer = null;
		Long l = null;
		String string = null;

		try
		{
			if (object instanceof Integer)
			{
				integer = (Integer) object;				
				ret = (Object) dataSource.load(Object.class, integer);
			}
			if (object instanceof Long)
			{
				l = (Long) object;
				ret = (Object) dataSource.load(Object.class, l);
			}		
			else if (object instanceof String)
			{
				string = (String) object;
				ret = (Object) dataSource.load(Object.class, string);
			}			
		}
		catch (ObjectNotFoundException e)
		{
			log.error("Method load: " + e);
			throw new DAOException(e.getMessage());
		}
		catch (Exception e)
		{
			log.error("Method load: " + e);
			throw new DAOException(e.getMessage());
		}
		
		return ret;
	}
	
	/**
	 * Returns the dataSource
	 * 
	 * @return
	 */
	public DataSource getDataSource() 
	{
		return dataSource;
	}

	/**
	 * Sets the dataSource
	 * 
	 * @param source
	 */
	public void setDataSource(DataSource source) 
	{
		dataSource = source;
	}
}

Então montei um DAO para os funcionarios extendendo esta classe:

public class EmployeeDAO extends AbstractHibernateDAO
{
    /**
     * Creates a new EmployeeDAO object.
     *
     * @param factory Session's Factory
     */
    public EmployeeDAO(SessionFactory factory)
    {
		super(factory);
    }

    /**
     * Verify if Employee's Register exists
     *
     * @param registration 	registration of employee
     * @param re 			re of employee
     *
     * @return boolean
     *
     * @throws Exception
     */
    public boolean existsEmployeeRegister(String registration, String re)
        throws Exception
    {
        boolean ret = false;

        int flagWhere = 0;
        ArrayList list = null;
        String query = "";

        ArrayList listObj = new ArrayList();
        ArrayList listType = new ArrayList();

        query = " from EmployeeRegisterTO reg ";

        if ((registration != null) && (!registration.equals("")))
        {
            query += " where reg.employee = ? ";
            listObj.add(registration);
            listType.add(Hibernate.STRING);
            flagWhere++;
        }

        if ((re != null) && (!re.equals("")))
        {
            if (flagWhere == 0)
            {
                query += " where";
            }
            else
            {
                query += " and";
            }

            query += " reg.re = ? ";
            listObj.add(re);
            listType.add(Hibernate.STRING);
            flagWhere++;
        }

        try
        {
            list = dataSource.find(query, listObj, listType);

            if ((list != null) && (list.size() > 0))
            {
                ret = true;
            }
        }
        catch (Exception e)
        {
            log.error("Method existsEmployeeRegister: " + e);
            throw new Exception("db.employee.existsEmployeeRegister.error");
        }

        return ret;
    }

Eu tento executar um create (herdado do Abstract) no EmployeeTO
da seguinte maneira:

        try
        {
            employeeDAO.create(employeeTO);
        }
        catch (Exception e)
        {
            throw e;
        }

É retornado um erro como se este método create não existisse…

java.lang.NoSuchMethodError: br.com.proj.dao.EmployeeDAO.create(Lbr/br/com/proj/model/to/register/EmployeeTO;)V
	at br.com.proj.model.bo.register.EmployeeBO.create(EmployeeBO.java:85)

Como se pode ver ele é herdado do AbstractHibernateDAO.

O que pode estar errado?

Obrigado,

Abraço!!!

dae tads,

O que é esse DataSource que vc usou.

Eu tenho uma session e para salvar um objeto uso session.save(obj). Porque vc está usando datasource.insert(obj)?

flw

Olá,

Este DataSource abstrai o acesso ao hibernate… ele não faz nada mais que abrir uma session, um transaction, executar um session.save(obj) e dar um commit.

Foi criado apenas para facilitar o uso e melhorar a performance
no desenvolvimento.

Depois de vários testes aki descobri qual era
o problema.
eu gerei um jar para o dao do projeto. dai eu colokei este dao
nos BO´s do projeto (que tinha o create de forma que tem que escrever toda hora a mesma coisa), MAS nao adicionei o novo jar do BO ao EAR
e ao projeto WEB.
Resultado: ele tava pegando o jar do BO antigo.

Valew