Hibernate 内连接查询 查不出数据 数据库能查出 20C

//客户实体类
public class Customer {

private Long cust_id;

private String cust_name;
private String cust_source;
private String cust_industry;
private String cust_level;
private String cust_linkman;
private String cust_phone;
private String cust_mobile;
//使用set集合,表达一对多关系 一个客户有很多个联系人
private Set<LinkMan> linkMens = new HashSet<LinkMan>();
public Long getCust_id() {
    return cust_id;
}
public void setCust_id(Long cust_id) {
    this.cust_id = cust_id;
}
public String getCust_name() {
    return cust_name;
}
public void setCust_name(String cust_name) {
    this.cust_name = cust_name;
}
public String getCust_source() {
    return cust_source;
}
public void setCust_source(String cust_source) {
    this.cust_source = cust_source;
}
public String getCust_industry() {
    return cust_industry;
}
public void setCust_industry(String cust_industry) {
    this.cust_industry = cust_industry;
}
public String getCust_level() {
    return cust_level;
}
public void setCust_level(String cust_level) {
    this.cust_level = cust_level;
}
public String getCust_linkman() {
    return cust_linkman;
}
public void setCust_linkman(String cust_linkman) {
    this.cust_linkman = cust_linkman;
}
public String getCust_phone() {
    return cust_phone;
}
public void setCust_phone(String cust_phone) {
    this.cust_phone = cust_phone;
}
public String getCust_mobile() {
    return cust_mobile;
}
public void setCust_mobile(String cust_mobile) {
    this.cust_mobile = cust_mobile;
}


public Set<LinkMan> getLinkMens() {
    return linkMens;
}
public void setLinkMens(Set<LinkMan> linkMens) {
    this.linkMens = linkMens;
}
@Override
public String toString() {
    return "Customer [cust_id=" + cust_id + ", cust_name=" + cust_name + "]";
}

}
//客户类配置hibernate映射文件











    <set name="linkMens" cascade="save-update">
        <key column="lkm_cust_id"></key>
        <one-to-many class="LinkMan"/>
    </set>
</class>

package com.jm.domain;
//联系人实体
public class LinkMan {

private Long lkm_id;
private Character lkm_gender;
private String lkm_name;
private String lkm_phone;
private String lkm_email;
private String lkm_qq;
private String lkm_mobile;
private String lkm_memo;
private String lkm_position;

//表达多对一关系很多个联系人属于一个客户
private Customer customer;
public Long getLkm_id() {
    return lkm_id;
}
public void setLkm_id(Long lkm_id) {
    this.lkm_id = lkm_id;
}
public Character getLkm_gender() {
    return lkm_gender;
}
public void setLkm_gender(Character lkm_gender) {
    this.lkm_gender = lkm_gender;
}
public String getLkm_name() {
    return lkm_name;
}
public void setLkm_name(String lkm_name) {
    this.lkm_name = lkm_name;
}
public String getLkm_phone() {
    return lkm_phone;
}
public void setLkm_phone(String lkm_phone) {
    this.lkm_phone = lkm_phone;
}
public String getLkm_email() {
    return lkm_email;
}
public void setLkm_email(String lkm_email) {
    this.lkm_email = lkm_email;
}
public String getLkm_qq() {
    return lkm_qq;
}
public void setLkm_qq(String lkm_qq) {
    this.lkm_qq = lkm_qq;
}
public String getLkm_mobile() {
    return lkm_mobile;
}
public void setLkm_mobile(String lkm_mobile) {
    this.lkm_mobile = lkm_mobile;
}
public String getLkm_memo() {
    return lkm_memo;
}
public void setLkm_memo(String lkm_memo) {
    this.lkm_memo = lkm_memo;
}
public String getLkm_position() {
    return lkm_position;
}
public void setLkm_position(String lkm_position) {
    this.lkm_position = lkm_position;
}

public Customer getCustomer() {
    return customer;
}
public void setCustomer(Customer customer) {
    this.customer = customer;
}
public LinkMan() {
}
public String toString() {
    return "LinkMan [lkm_id=" + lkm_id + ", lkm_gender=" + lkm_gender + ", lkm_name=" + lkm_name + ", lkm_phone="
            + lkm_phone + ", lkm_email=" + lkm_email + ", lkm_qq=" + lkm_qq + ", lkm_mobile=" + lkm_mobile
            + ", lkm_memo=" + lkm_memo + ", lkm_position=" + lkm_position + "]";
}

}
//联系人类配置hibernate映射文件




        <property name="lkm_gender" column="lkm_gender"></property>
        <property name="lkm_name" column="lkm_name" type="string"></property>
        <property name="lkm_phone" column="lkm_phone" type="java.lang.String"></property>
        <property name="lkm_email" column="lkm_email" type="java.lang.String"></property>
        <property name="lkm_qq" column="lkm_qq" type="java.lang.String"></property>
        <property name="lkm_mobile" column="lkm_mobile" type="java.lang.String"></property>
        <property name="lkm_memo" column="lkm_memo" type="java.lang.String"></property>
        <property name="lkm_position" column="lkm_position" type="java.lang.String"></property>

    <many-to-one name="customer" column="lkm_cust_id" class="Customer" >
    </many-to-one>
    </class>
</hibernate-mapping>

public class Demo2 {

public static void fun() {
    Session session = HibernateUtils.openSession();
    Transaction tx = session.beginTransaction();
    //----------------------------------------------------
    String hql = " from Customer c inner join fetch c.linkMens ";

    Query query = session.createQuery(hql);

    List<Customer> list = query.list();
    System.out.println(list);
    //----------------------------------------------------
    tx.commit();
    session.close();
}

public static void main(String[] args) {
    fun();
}

}

2个回答

jdbc.数据库配错了吧

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