日期:2014-05-20  浏览次数:20773 次

hibernate在update操作时提示unexpected AST node错误
update操作如下
Java code
        Transaction txUpdate = sess.beginTransaction();

        Query update=sess.createQuery("update ProjectSummary ps set ps.bean3dot1 = :bean3dot1 where ps.id = :id")
            .setEntity("bean3dot1", bean3dot1)
            .setInteger("id", (Integer) session.get("ID"));
        update.executeUpdate();
        txUpdate.commit();


其中ProjectSummary是由几个组建组成的表,ProjectSummary.hbm.xml如下
XML code
<?xml version="1.0" encoding="GBK"?>
<!-- 指定Hiberante3映射文件的DTD信息 -->
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- hibernate-mapping是映射文件的根元素 -->
<hibernate-mapping package="project">
    <!-- 每个class元素对应一个持久化对象 -->
    <class name="ProjectSummary" table="ProjectSummary">
        <!-- id元素定义持久化类的标识属性 -->
        <id name="id">
            <!-- 指定主键生成策略 -->
            <generator class="foreign">
                <param name="property">ProjectRecord</param>
            </generator>
        </id>
        <component name="bean3dot1" class="page.Page3dot1">
            <property name="ShortName"/>
            <property name="Location"/>
            <property name="ProjectGrade"/>
            <property name="InstalledCapacity"/>
            <property name="NormalHighWaterLevel"/>
            <property name="DeadWaterLevel"/>
            <property name="TotalStorage"/>
            <property name="EffectStorage"/>
        </component>
        <component name="bean3dot2" class="page.Page3dot2">
            <property name="EarthrockExcavation"/>
            <property name="EarthrockFillback"/>
            <property name="WasteDisposalCapacity"/>
            <property name="WasteDisposalAreaNumber"/>
        </component>
        <component name="bean3dot3" class="page.Page3dot3">
            <property name="LandRequisitionArea"/>
            <property name="LandRequisitionArea_Permanent"/>
            <property name="LandRequisitionArea_Temporary"/>
            <property name="MajorArea"/>
            <property name="SubmergeArea"/>
        </component>
        <component name="bean3dot4" class="page.Page3dot4">
            <property name="MigrationPopulation"/>
            <property name="ResettlementPopulation"/>
        </component>
        <component name="bean3dot5" class="page.Page3dot5">
            <property name="StaticInvestment"/>
            <property name="ConstructionInvestment"/>
        </component>
        <!-- one-to-one -->
        <one-to-one name="ProjectRecord"/>
    </class>
</hibernate-mapping>



ProjectSummary.java
Java code
package project;

import page.*;
public class ProjectSummary
{
    private Integer id;
    
    public void setId(Integer id)
    {
        this.id = id;
    }
    public Integer getId()
    {
        return this.id;
    }
    
    //3.1
    private Page3dot1 bean3dot1;
    
    public Page3dot1 getBean3dot1()
    {
        return this.bean3dot1;
    }
    
    public void setBean3dot1(Page3dot1 bean3dot1)
    {
        this.bean3dot1=bean3dot1;
    }
    
    //3.2
    private Page3dot2 bean3dot2;
    
    public Page3dot2 getBean3dot2()
    {
        return this.bean3dot2;
    }
    
    public void setBean3dot2(Page3dot2 bean3dot2)
    {
        this.bean3dot2=bean3dot2;
    }
    
    //3.3
    private Page3dot3 bean3dot3;
    
    public Page3dot3 getBean3dot3()
    {
        return this.bean3dot3;
    }
    
    public void setBean3dot3(Page3dot3 bean3dot3)
    {
        this.bean3dot3=bean3dot3;
    }
    
    //3.4
    private Page3dot4 bean3dot4;
    
    public Page3dot4 getBean3dot4()
    {
        return this.bean3dot4;
    }
    
    public void setBean3dot4(Page3dot4 bean3dot4)
    {
        this.bean3dot4=bean3dot4;
    }
    
    //3.5
    private Page3dot5 bean3dot5;
    
    public Page3dot5 getBean3dot5()
    {
        return this.bean3dot5;
    }
    
    public void setBean3dot5(Page3dot5 bean3dot5)
    {
        this.bean3dot5=bean3dot5;
    }
    
    //关联的属性
    private ProjectRecord pr;
    
    public void setProjectRecord(ProjectRecord pr)
    {
        this.pr=pr;
    }
    
    public ProjectRecord getProjectRecord()
    {
        return this.pr;
    }    
}