weixin_42423440 2011-03-14 10:47
浏览 162
已采纳

hibernate 外键问题

有外键关系的几个表,要做类似这样的查询:select hbiNId from hrBranchInfo where hbi_n_prior=? and hbiVname=? and hbiCState=1;

问题可能出现在红色标注的字段。下面是代码,大家看看问题出在了哪。

 

报错:org.hibernate.hql.ast.QuerySyntaxException: hrBranchInfo is not mapped. [select hbiNId from hrBranchInfo where hbi_n_prior=? and hbiVname=? and hbiCState=1]

 

映射:

hibernate-mapping>
    <class name="com.pojo.HrBranchInfo" table="hr_branch_info" schema="public">
        <id name="hbiNId" type="java.lang.Integer">
            <column name="hbi_n_id" />
            <generator class="sequence" />
        </id>
        <many-to-one name="hrEmpBase" class="com.pojo.HrEmpBase" fetch="select">
            <column name="hbi_n_operator" />
        </many-to-one>
        <many-to-one name="hrBranchInfo" class="com.pojo.HrBranchInfo" fetch="select">
            <column name="hbi_n_prior" not-null="false" />
        </many-to-one>
        <property name="hbiVName" type="java.lang.String">
            <column name="hbi_v_name" length="40" not-null="true" />
        </property>
        <property name="hbiCState" type="java.lang.String">
            <column name="hbi_c_state" length="1" not-null="true" />
        </property>
        <property name="hbiVDesc" type="java.lang.String">
            <column name="hbi_v_desc" length="200" />
        </property>
        <property name="hbiCTime" type="java.lang.String">
            <column name="hbi_c_time" length="14" />
        </property>
        <property name="hbiNSortindex" type="java.lang.String">
            <column name="hbi_n_sortindex" length="10" />
        </property>
        <property name="hbiVTemp1" type="java.lang.String">
            <column name="hbi_v_temp1" length="100" />
        </property>
        <property name="hbiVTemp2" type="java.lang.String">
            <column name="hbi_v_temp2" length="100" />
        </property>
        <property name="hbiVTemp3" type="java.lang.String">
            <column name="hbi_v_temp3" length="100" />
        </property>
        <set name="hrEmpBases" inverse="true">
            <key>
                <column name="hbi_n_id" not-null="true" />
            </key>
            <one-to-many class="com.pojo.HrEmpBase" />
        </set>
        <set name="hrRelationBranduties" inverse="true">
            <key>
                <column name="hbi_n_id" not-null="true" />
            </key>
            <one-to-many class="com.pojo.HrRelationBranduty" />
        </set>
        <set name="hrBranchInfos" inverse="true">
            <key>
                <column name="hbi_n_prior" not-null="true" />
            </key>
            <one-to-many class="com.pojo.HrBranchInfo" />
        </set>
    </class>
</hibernate-mapping>

 dao:

  //检查部门名称有效性
    public boolean check(HrBranchInfo hbi){
        String queryString = "select hbiNId from hrBranchInfo where hbi_n_prior=? and hbiVname=? and hbiCState=1";
        
        try {
            Query query = getSession().createQuery(queryString);
            List lst = query.list();
            if(lst.size() > 0){
                return true;
            }else {
                return false;
            }
        } catch (HibernateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }

 实体类。

package com.pojo;

import java.util.HashSet;
import java.util.Set;

/**
 * HrBranchInfo entity. @author MyEclipse Persistence Tools
 */

public class HrBranchInfo implements java.io.Serializable {

    // Fields

    private Integer hbiNId;
    private HrEmpBase hrEmpBase;
    private HrBranchInfo hrBranchInfo;
    private String hbiVName;
    private String hbiCState;
    private String hbiVDesc;
    private String hbiCTime;
    private String hbiNSortindex;
    private String hbiVTemp1;
    private String hbiVTemp2;
    private String hbiVTemp3;
    private Set hrRelationBranduties = new HashSet(0);
    private Set hrBranchInfos = new HashSet(0);

    // Constructors

    /** default constructor */
    public HrBranchInfo() {
    }

    /** minimal constructor */
    public HrBranchInfo(HrBranchInfo hrBranchInfo, String hbiVName,
            String hbiCState) {
        this.hrBranchInfo = hrBranchInfo;
        this.hbiVName = hbiVName;
        this.hbiCState = hbiCState;
    }

    /** full constructor */
    public HrBranchInfo(HrEmpBase hrEmpBase, HrBranchInfo hrBranchInfo,
            String hbiVName, String hbiCState, String hbiVDesc,
            String hbiCTime, String hbiNSortindex, String hbiVTemp1,
            String hbiVTemp2, String hbiVTemp3, Set hrRelationBranduties,
            Set hrBranchInfos) {
        this.hrEmpBase = hrEmpBase;
        this.hrBranchInfo = hrBranchInfo;
        this.hbiVName = hbiVName;
        this.hbiCState = hbiCState;
        this.hbiVDesc = hbiVDesc;
        this.hbiCTime = hbiCTime;
        this.hbiNSortindex = hbiNSortindex;
        this.hbiVTemp1 = hbiVTemp1;
        this.hbiVTemp2 = hbiVTemp2;
        this.hbiVTemp3 = hbiVTemp3;
        this.hrRelationBranduties = hrRelationBranduties;
        this.hrBranchInfos = hrBranchInfos;
    }

    // Property accessors

    public HrBranchInfo(String hbiVName, Set hrBranchInfos, String hbiCState,String hbiVDesc,
            String hbiCTime, String hbiNSortindex) {
        super();
        this.hbiVName = hbiVName;
        this.hrBranchInfos = hrBranchInfos;
        this.hbiCState = hbiCState;
        this.hbiVDesc = hbiVDesc;
        this.hbiCState = hbiCTime;
        this.hbiNSortindex = hbiNSortindex;
    }

    public Integer getHbiNId() {
        return this.hbiNId;
    }

    public void setHbiNId(Integer hbiNId) {
        this.hbiNId = hbiNId;
    }

    public HrEmpBase getHrEmpBase() {
        return this.hrEmpBase;
    }

    public void setHrEmpBase(HrEmpBase hrEmpBase) {
        this.hrEmpBase = hrEmpBase;
    }

    public HrBranchInfo getHrBranchInfo() {
        return this.hrBranchInfo;
    }

    public void setHrBranchInfo(HrBranchInfo hrBranchInfo) {
        this.hrBranchInfo = hrBranchInfo;
    }

    public String getHbiVName() {
        return this.hbiVName;
    }

    public void setHbiVName(String hbiVName) {
        this.hbiVName = hbiVName;
    }

    public String getHbiCState() {
        return this.hbiCState;
    }

    public void setHbiCState(String hbiCState) {
        this.hbiCState = hbiCState;
    }

    public String getHbiVDesc() {
        return this.hbiVDesc;
    }

    public void setHbiVDesc(String hbiVDesc) {
        this.hbiVDesc = hbiVDesc;
    }

    public String getHbiCTime() {
        return this.hbiCTime;
    }

    public void setHbiCTime(String hbiCTime) {
        this.hbiCTime = hbiCTime;
    }

    public String getHbiNSortindex() {
        return this.hbiNSortindex;
    }

    public void setHbiNSortindex(String hbiNSortindex) {
        this.hbiNSortindex = hbiNSortindex;
    }

    public String getHbiVTemp1() {
        return this.hbiVTemp1;
    }

    public void setHbiVTemp1(String hbiVTemp1) {
        this.hbiVTemp1 = hbiVTemp1;
    }

    public String getHbiVTemp2() {
        return this.hbiVTemp2;
    }

    public void setHbiVTemp2(String hbiVTemp2) {
        this.hbiVTemp2 = hbiVTemp2;
    }

    public String getHbiVTemp3() {
        return this.hbiVTemp3;
    }

    public void setHbiVTemp3(String hbiVTemp3) {
        this.hbiVTemp3 = hbiVTemp3;
    }

    public Set getHrRelationBranduties() {
        return this.hrRelationBranduties;
    }

    public void setHrRelationBranduties(Set hrRelationBranduties) {
        this.hrRelationBranduties = hrRelationBranduties;
    }

    public Set getHrBranchInfos() {
        return this.hrBranchInfos;
    }

    public void setHrBranchInfos(Set hrBranchInfos) {
        this.hrBranchInfos = hrBranchInfos;
    }

}

请大家帮下忙,谢谢!

  • 写回答

5条回答 默认 最新

  • redstarofsleep 2011-03-14 10:52
    关注

    [code="java"]
    select hbiNId from hrBranchInfo where hrBranchInfos=? and hbiVname=? and hbiCState=1;
    [/code]
    改成这样试试

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计