此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【venus224】截止到2008-07-29 21:12:09的历史汇总数据(不包括此帖):
发帖的总数量:12                       发帖的总分数:260                      每贴平均分数:21                       
回帖的总数量:17                       得分贴总数量:2                        回帖的得分率:11%                      
结贴的总数量:12                       结贴的总分数:260                      
无满意结贴数:6                        无满意结贴分:100                      
未结的帖子数:0                        未结的总分数:0                        
结贴的百分比:100.00%               结分的百分比:100.00%                  
无满意结贴率:50.00 %               无满意结分率:38.46 %                  
敬礼!

取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=venus224

解决方案 »

  1.   

    你这样不符合hibernate的机制吧
    他操作的都是对象。
    既然你把他当做属性 那也只是你这个表中的属性,而不能说明是其他表(对象)的属性啊。
    也就是你可以用这个属性对你当前的这个对象进行操作。
      

  2.   

    我在数据库中是有外键!
    那样会出什么麻烦?
    能不能给我一个级联删除和更新的例子
    邮箱:[email protected]
      

  3.   

    你那样做插入的话也只是一个表中的字段啊。
    当然你如果这个字段在另外个表中当主键  而你当前的pojo里面写了这个字段做为普通字段
     数据库中没有这个字段
     插入的时候当然会出错啊。
    这样做没多大意义!!
      

  4.   

    那我要怎么处理外键呢?
    外键全部映射成对象了!
    我在update,insert时如何对这个对象操作呢?
    假设我的pojo类是 Employee。我要更新 enterprise_ID这个字段,可是这个字段映射成对象:TEnterprise
    <many-to-one name="TEnterprise" class="com.ehr.vo.TEnterprise" fetch="select"> 
                <column name="enterprise_ID" not-null="true" /> 
    </many-to-one>
    public ActionForward update(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
         TEmployeeForm temployeeForm=new TEmployeeForm();
         TEmployee temployee=new TEmployee();
         这里如何保存从页面传过来的数据?
         temployee.setTEnterprise(temployeForm.getTEnterprise())---这里会出错!
    }
    actionform和pojo要做哪些变动?要不要自己添加employeeId?
    actionform中是写employeeId还是TEnterprise;
      

  5.   

    那我要怎么处理外键呢? 
    外键全部映射成对象了! 
    我在update,insert时如何对这个对象操作呢? 
    假设我的pojo类是 Employee。我要更新 enterprise_ID这个字段,可是这个字段映射成对象:TEnterprise 
    <many-to-one name="TEnterprise" class="com.ehr.vo.TEnterprise" fetch="select"> 
                <column name="enterprise_ID" not-null="true" /> 
    </many-to-one> 
    public ActionForward update(ActionMapping mapping, ActionForm form, 
    HttpServletRequest request, HttpServletResponse response) { 
        TEmployeeForm temployeeForm=new TEmployeeForm(); 
        TEmployee temployee=new TEmployee(); 
        这里如何保存从页面传过来的数据? 
        temployee.setTEnterprise(temployeForm.getTEnterprise())---这里会出错! 

    actionform和pojo要做哪些变动?要不要自己添加employeeId? 
    actionform中是写employeeId还是TEnterprise; 
      

  6.   


    数据库中都有关联,Hibernate中不要,操作数据库时不会出错吗?
    比如:用户自己输入一个外键值添加数据。
      

  7.   

    你就是想把t_node表的enterprise_ID字段更新成enterprise表里的另一个值对吧
    大概代码如下
    TEnterprise tEnterprise = new TEnterprise();
    tEnterprise.setPersonID(71);//如果你的是从form中取得,那要确认temployeForm.getTEnterprise()中的TEnterprise的id在数据库的表中是否有对应 TEmployee temployee = new TEmployee();
    temployee.setTEnterprise(tEnterprise);
    ......
    getHibernateTemplate().saveOrUpdate(temployee);
      

  8.   

    最好别用hiberntate的级联约束,容易出错,用程序控制吧,反正你数据库中都做了约束。