为什么JPA会为数据库生成如此多的select语句

时间:2018-01-30 15:28:58

标签: java spring-boot spring-data-jpa

我想比较JPA和JDBCTemplate。 在这种情况下,我实现了两个方法,一个用于JDBCTemplate,一个用于JPA,如bellow。

JPA

public List<Products> listProductsSortedByProductName() {
    List<Products> productList = jpaProductRepository.findAll(new Sort(Sort.Direction.ASC, "productname"));
    return productList;
}

的JdbcTemplate

    public List<Products>listProductsSortedByProductName() {
    String sql = "SELECT * FROM products order by ProductName asc";
    List<Products> productList = jdbcTemplate.query(sql, productsRowMapper);
    return productList;
}

实体产品

@Entity
public class Products {
  @Id
  @GeneratedValue
  private Long productid;
  private String productname;
  @JoinColumn(name = "supplierid", referencedColumnName = "SupplierID")
  @ManyToOne
  private Suppliers supplierid;
  @JoinColumn(name = "categoryid", referencedColumnName = "CategoryID")
  @ManyToOne
  private Categories categoryid;
  private String quantityperunit;
  private Double unitprice;
  private Long unitsinstock;
  private Long unitsonorder;
  private Long reorderlevel;
  private Boolean discontinued;

  public Products() {
  }

  public Products(String productname, Suppliers supplierid, Categories categoryid, String quantityperunit, Double unitprice, Long unitsinstock, Long unitsonorder, Long reorderlevel, Boolean discontinued) {
    this.productname = productname;
    this.supplierid = supplierid;
    this.categoryid = categoryid;
    this.quantityperunit = quantityperunit;
    this.unitprice = unitprice;
    this.unitsinstock = unitsinstock;
    this.unitsonorder = unitsonorder;
    this.reorderlevel = reorderlevel;
    this.discontinued = discontinued;
  }

  public Long getProductid() {
    return productid;
  }

//getters and setters here

  @Override
  public String toString() {
    return "Products{" +
            "productid=" + productid +
            ", productname='" + productname + '\'' +
            ", supplierid=" + supplierid +
            ", categoryid=" + categoryid +
            ", quantityperunit='" + quantityperunit + '\'' +
            ", unitprice=" + unitprice +
            ", unitsinstock=" + unitsinstock +
            ", unitsonorder=" + unitsonorder +
            ", reorderlevel=" + reorderlevel +
            ", discontinued='" + discontinued + '\'' +
            '}';
  }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Products products = (Products) o;

        return productid.equals(products.productid);
    }

    @Override
    public int hashCode() {
        return productid.hashCode();
    }
}

实体类别

@Entity
public class Categories {
  @Id
  @GeneratedValue
  private Long categoryid;
  private String categoryname;
  private String description;
  private String picture;

  @OneToMany(mappedBy="categoryid")
  private List<Products> products;

    public Categories(String categoryname) {
        this.categoryname = categoryname;
    }

    public Categories() {
    }

    public Categories(String categoryname, String description) {
        this.categoryname = categoryname;
        this.description = description;
    }


  public Long getCategoryid() {
    return categoryid;
  }

//getters and setters here

    @Override
    public String toString() {
        return "Categories{" +
                "categoryid=" + categoryid +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Categories that = (Categories) o;

        return categoryid.equals(that.categoryid);
    }

    @Override
    public int hashCode() {
        return categoryid.hashCode();
    }
}

实体供应商

@Entity
public class Suppliers {
  @Id
  @GeneratedValue
  private Long supplierid;
  private String companyname;
  private String contactname;
  private String contacttitle;
  private String address;
  private String city;
  private String region;
  private String postalcode;
  private String country;
  private String phone;
  private String fax;
  private String homepage;

  @OneToMany(mappedBy="supplierid")
  private List<Products> products;

  public Suppliers(String companyname, String contactname, String contacttitle, String address, String city, String region, String postalcode, String country, String phone, String fax, String homepage) {
    this.companyname = companyname;
    this.contactname = contactname;
    this.contacttitle = contacttitle;
    this.address = address;
    this.city = city;
    this.region = region;
    this.postalcode = postalcode;
    this.country = country;
    this.phone = phone;
    this.fax = fax;
    this.homepage = homepage;
  }

  public Suppliers() {
  }

  public Suppliers(String companyname) {
    this.companyname = companyname;
  }

 //getters and setters here

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Suppliers suppliers = (Suppliers) o;

    return supplierid != null ? supplierid.equals(suppliers.supplierid) : suppliers.supplierid == null;
  }

  @Override
  public int hashCode() {
    return supplierid != null ? supplierid.hashCode() : 0;
  }

  @Override
  public String toString() {
    return "Suppliers{" +
            "supplierid=" + supplierid +
            '}';
  } 
}

当我运行程序时,我发现JPA生成了很多选择语句

Hibernate: select products0_.productid as producti1_9_, products0_.categoryid as category9_9_, products0_.discontinued as disconti2_9_, products0_.productname as productn3_9_, products0_.quantityperunit as quantity4_9_, products0_.reorderlevel as reorderl5_9_, products0_.supplierid as supplie10_9_, products0_.unitprice as unitpric6_9_, products0_.unitsinstock as unitsins7_9_, products0_.unitsonorder as unitsono8_9_ from products products0_ order by products0_.productname asc
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select categories0_.categoryid as category1_4_0_, categories0_.categoryname as category2_4_0_, categories0_.description as descript3_4_0_, categories0_.picture as picture4_4_0_ from categories categories0_ where categories0_.categoryid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?
Hibernate: select suppliers0_.supplierid as supplier1_12_0_, suppliers0_.address as address2_12_0_, suppliers0_.city as city3_12_0_, suppliers0_.companyname as companyn4_12_0_, suppliers0_.contactname as contactn5_12_0_, suppliers0_.contacttitle as contactt6_12_0_, suppliers0_.country as country7_12_0_, suppliers0_.fax as fax8_12_0_, suppliers0_.homepage as homepage9_12_0_, suppliers0_.phone as phone10_12_0_, suppliers0_.postalcode as postalc11_12_0_, suppliers0_.region as region12_12_0_ from suppliers suppliers0_ where suppliers0_.supplierid=?

你能解释一下为什么会这样吗,也许我做错了什么?

1 个答案:

答案 0 :(得分:1)

因为渴望获取。始终使用@ManyToOne(fetch = FetchType.LAZY)