兄弟姐妹们过来帮忙看下~搞了半天了!

页面显示错误:



 

控制台显示错误:



 

formBean:

private CRecruitment crecruitment=new CRecruitment();
    
    public CRecruitment getCrecruitment() {
        return crecruitment;
    }

    public void setCrecruitment(CRecruitment recruitment) {
        crecruitment = recruitment;
    }

 

hibernate 映射:

   CRecruitment:

 <many-to-one name="cposition" class="com.igolf.entity.CPosition" fetch="join" cascade="all"  lazy="false">
            <column name="POSITION_ID" />
        </many-to-one>

 

   CPosition:

  <set name="crecruitments" inverse="true" lazy="false" cascade="all">
            <key>
                <column name="POSITION_ID" />
            </key>
            <one-to-many class="com.igolf.entity.CRecruitment" />
        </set>

 form 已经注入

 

jsp页面代码是:

<p class="first">                   
            <label>&nbsp;&nbsp;&nbsp;&nbsp;编号:</label>                
            <input type="text" name="crecruitment.id" size="30" readonly="readonly" value="${crecruitment.id }"/>                 
        </p>
        <p>                   
          <label>职位名称:</label>    
            <input type="text" name="crecruitment.cposition.id" size="30" value="${crecruitment.cposition.position }"/>
            <!--  <select name="crecruitment.cposition.id" >
            <c:forEach items="${cposition}" var="xx">
            <option selected="selected" value="${ xx.id }">${xx.position}</option>
            </c:forEach>
            </select>-->
        </p>
        <p>
            <label>发布日期:</label>              
            <input type="text" name="crecruitment.date" size="30" value="${crecruitment.date }"/> *
        </p>  

 

执行的操作时要保存信息,好久没写了,不知道是不是hibernate多对一的配置问题!

5个回答

改了之后再插入mysql错误 就说明这个form问题已经解决了

插入错误有可能是crecruitment里没set cposition,插入前
先crecruitment.setCposition(cposition);

你可以在插入前先把crecruitment的属性全部System.out.println();一下 看看有没有都设置好了 包括crecruitment里cposition的id和positon

有在struts-config里定义formbean嚒
[code="java"] [/code]

我觉得是form bean那个java代码的问题

外键没有设置好,你在input里有crecruitment.cposition.id和 crecruitment.cposition.position ,应该是这个position对象没new出来,所以不能设置

如果是因为CPosition的原因,换种思路,要不你就在formbean里定义一个CPosition

[code="java"]private CPosition cposition=new CPosition();
private CRecruitment crecruitment=new CRecruitment();

public CRecruitment getCrecruitment() {
    return crecruitment;
}

public void setCrecruitment(CRecruitment recruitment) {
    crecruitment = recruitment;
}

CPosition getter setter。。。
input里用cposition.id 不要用crecruitment.cposition.id,position字段也一样
[/code]

或者就在CRecruitment类的构造函数里,直接给cposition也new一个出来

[code="jsp"]

[/code]
看你的代码中crecruitment类中是有cposition对象。你试一试把crecruitment类中cposition对象属性new一下!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐