第一次做泛型,我在这里有点困惑。类型GenericDao <Order,capture#2-of?>中的方法read(capture#2 of?)不适用于参数(Long)
我有以下几点:
public interface GenericDao<T, PK extends java.io.Serializable> {
/**
* Retrieve an object that was previously persisted to the database
* using the reference id as primary key
*
* @param id primary key
* @return
*/
public T read(PK id);
}
public class GenericDaoHibernateImpl<T, PK extends java.io.Serializable> implements GenericDao<T, PK>
{
private Class<T> type;
private SessionFactory sessionFactory;
/**
*
*/
public GenericDaoHibernateImpl(Class<T> type)
{
this.type = type;
}
@SuppressWarnings("unchecked")
public T read(final PK id)
{
return (T) getSession().get(type, id);
}
}
<bean id="orderDao" class="vsg.ecotrak.framework.dao.GenericDaoHibernateImpl">
<constructor-arg>
<value>vsg.ecotrak.common.order.domain.Order</value>
</constructor-arg>
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
然后我的服务类只是调用了this.getOrderDao()读取(PID)PID是通过对服务类的长期负载方法。
你有OrderDao的代码吗? – Pace 2010-11-12 04:54:56
<豆ID = “orderDao” 类= “vsg.ecotrak.framework.dao.GenericDaoHibernateImpl”> <构造精氨酸> vsg.ecotrak.common.order.domain.Order 构造精氨酸> <属性名=“SessionFactory的”> –
boyd4715
2010-11-12 05:00:35
你应该标题改成你的问题有点像“我如何获得仿制药在一个Spring上下文中工作吗?”然后在您的问题文本中包含例外。这将使人们更容易找到以后。 – 2010-11-12 07:49:38