spring+Hibernate執行時出錯,各位大哥幫忙啊!!!!!!!!!!!!!!!!!!!

jacky198210發表於2004-06-25
我想得到表T_Bidding_QuestAndAnswerAnnex的全部欄位、表T_Base_Project部分欄位 內容
(我用了引用project物件,"many-to-one";而事實上我只需要project.projectname一個欄位,不知道該怎麼做,只好
包函它的全部內容了!),在執行:list("AHPTC-2004-107", 174) 測試時出錯了?????????????

LOG資訊如下:
--------------->1
Hibernate: select top 10 questandan0_.id as id0_, project1_.projectid as projectid1_, questandan0_.projectid as projectid0_, questandan0_.enterpriseid as enterpri3_0_, questandan0_.filename as filename0_, questandan0_.memo as memo0_, questandan0_.state as state0_, questandan0_.oldfilename as oldfilen7_0_, questandan0_.uploadtime as uploadtime0_, project1_.projectcode as projectc2_1_, project1_.projectname as projectn3_1_, project1_.projectcontent as projectc4_1_, project1_.enterpriseid as enterpri5_1_, project1_.employeeid as employeeid1_, project1_.projecttype as projectt7_1_, project1_.projectmode as projectm8_1_, project1_.chargemode as chargemode1_, project1_.sum as sum1_, project1_.biddingdate as bidding11_1_, project1_.biddingtime as bidding12_1_, project1_.projectintroduce as project13_1_, project1_.state as state1_, project1_.loginname as loginname1_, project1_.password as password1_, project1_.memo as memo1_, project1_.recorderdate as recorde18_1_, project1_.isdispartment as isdispa19_1_ from T_Bidding_QuestAndAnswerAnnex questandan0_ inner join T_Base_Project project1_ on questandan0_.projectid=project1_.projectid where (project1_.projectcode=? ) order by questandan0_.projectid
net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.ahptc.bo.Project.setSum
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:212)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2199)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:240)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1536)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.ahptc.service.dao.hibernate.QuestAnnexHibernateDAO$1.doInHibernate(QuestAnnexHibernateDAO.java:64)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:150)
at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:170)
at com.ahptc.service.dao.hibernate.QuestAnnexHibernateDAO.list(QuestAnnexHibernateDAO.java:43)
at com.ahptc.action.DownQuestionAction.execute(DownQuestionAction.java:57)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at com.ahptc.tp.servlet.EncodeFilter.doFilter(EncodeFilter.java:61)
..............................

相關程式碼貼出如下:

這是執行的程式碼QuestAnnexHibernateDAO:
public List list(final String projectCode, final int enterpriseId) {
sb.append("from bo.QuestAndAnswerAnnex annex ");
sb.append("join annex.project as project ");
sb.append("where annex.project.projectcode = :projectcode ");
sb.append("order by annex.projectid");
Query query = session.createQuery(sb.toString());
query.setString("projectcode", projectCode);
System.out.println(" --------------->1 "+);
List list=null;
try{
list = query.list();
}catch(Exception e){
e.printStackTrace();
}
//session.close();
System.out.println("--------------->>>>>> "+list.size());
return list;
}
});
}

以下是spring配置檔案applicationContext-hibernate.xml:
...
<property name="mappingResources">
<list>
<value>bo/QuestAndAnswerAnnex.hbm.xml</value>
<value>bo/Project.hbm.xml</value>
</list>
</property>
...
<bean id="questAnnexDAO" class="dao.hibernate.QuestAnnexHibernateDAO">
<property name="sessionFactory"><ref local="mySessionFactory"/></property>
</bean>

以下是QuestAndAnswerAnnex.java檔案內容:
public class QuestAndAnswerAnnex implements Serializable {
...
private Project project;
...
}

以下是Project.java檔案內容:
public class Project implements Serializable {
...
private Set questAnnex= new HashSet();
...
}

以下是QuestAndAnswerAnnex.hbm.xml檔案內容:
<hibernate-mapping>
<class name="bo.QuestAndAnswerAnnex" table="T_Bidding_QuestAndAnswerAnnex">
<composite-id >
<key-property name="projectid" column="projectid" type="integer" length="4"/>
<key-property name="enterpriseid" column="enterpriseid" type="integer" length="4"/>
</composite-id>
<property name="filename" column="filename" type="string" length="100"/>
...
<property name="id" column="id" type="integer" length="4" not-null="true"/>
<many-to-one
name="project"
class="bo.Project"
cascade="none"
outer-join="auto"
update="false"
insert="false"
column="projectid"
/>
</class>
</hibernate-mapping>

以下是Project.hbm.xml檔案內容:
<hibernate-mapping>
<class name="bo.Project" table="T_Base_Project">
<id name="projectid" column="projectid" type="integer" length="4">
<generator class="uuid.hex"/>
</id>
<property name="projectcode" column="projectcode" type="string" length="100"/>
<property name="projectname" column="projectname" type="string" length="500" not-null="true"/>
<property name="enterpriseid" column="enterpriseid" type="string" length="500"/>
<property name="projectintroduce" column="projectintroduce" type="serializable"/> //type="serializable"此對應的是表中text型別
...
<set name="questAnnex" inverse="true" lazy="true" cascade="all">
<key column="projectid"/>
<one-to-many class="bo.QuestAndAnswerAnnex"/>
</set>
</class>
</hibernate-mapping>

相關文章