spring+Hibernate执行时出错,各位大哥帮忙啊!!!!!!!!!!!!!!!!!!!

04-06-25 jacky198210
我想得到表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>

jacky198210
2004-06-25 12:27
怎么XML标签不能贴上去啊????????

banq
2004-06-27 18:49
代码需要选择Code按钮。

从这个报错来看:Spring+Hibernate 并不比Sesssion Bean+CMP简单多,实际上,面向应用的技术简单化没有很大差别,没有银弹啊。

猜你喜欢