第一次做泛型,我在這裏有點困惑。類型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