【问题标题】:could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet无法提取结果集; SQL [不适用];嵌套异常是 org.hibernate.exception.SQLGrammarException: could not extract ResultSet
【发布时间】:2017-11-08 00:24:09
【问题描述】:

我的存储库中有该 nativeQuery 查询。

 @Query(value = "Select * from Company a  left join Industry b on a.industry_id=b.id", nativeQuery = true)
    public List < Company > findJoin();

但是当我运行页面时出现了这个错误

无法提取结果集; SQL [不适用];嵌套异常是 org.hibernate.exception.SQLGrammarException:无法提取 结果集

Company

  @Entity
  public class Company {

    private long id;

    private String name;
    private String website;
    private String about;
    private String city;
    private int location;
    private int industry_id;


    /**
     * @return the industry_id
     */
    public int getIndustry_id() {
        return industry_id;
    }

    /**
     * @param industry_id the industry_id to set
     */
    public void setIndustry_id(int industry_id) {
        this.industry_id = industry_id;
    }

    private int numbere;

    private Industry industry;

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long getId() {
        return id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the website
     */
    public String getWebsite() {
        return website;
    }

    /**
     * @param website
     *            the website to set
     */
    public void setWebsite(String website) {
        this.website = website;
    }

    /**
     * @return the about
     */
    public String getAbout() {
        return about;
    }

    /**
     * @param about
     *            the about to set
     */
    public void setAbout(String about) {
        this.about = about;
    }

    /**
     * @return the city
     */
    public String getCity() {
        return city;
    }

    /**
     * @param city
     *            the city to set
     */
    public void setCity(String city) {
        this.city = city;
    }

    /**
     * @return the location
     */
    public int getLocation() {
        return location;
    }

    /**
     * @param location
     *            the location to set
     */
    public void setLocation(int location) {
        this.location = location;
    }

    /**
     * @return the industry_id
     */


    /**
     * @param industry_id
     *            the industry_id to set
     */


    /**
     * @return the numbere
     */
    public int getNumbere() {
        return numbere;
    }

    /**
     * @param numbere
     *            the numbere to set
     */
    public void setNumbere(int numbere) {
        this.numbere = numbere;
    }

    /**
     * @return the industry
     */
    @ManyToOne
    @JoinColumn(name = "industry_id",insertable = false, updatable = 
  false)
    public Industry getIndustry() {
        return industry;
    }

    /**
     * @param industry
     *            the industry to set
     */
    public void setIndustry(Industry industry) {
        this.industry = industry;
    }

    // private byte[] logo;

   }

行业

 @Entity
public class Industry {

    @Column(name="ides")
    private long id;
    @Column(name="namens")
    private String name;


    private Set<Company> company;


    /**
     * @return the id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the company
     */
    @OneToMany(mappedBy = "industry", cascade = CascadeType.ALL)
    public Set<Company> getCompany() {
        return company;
    }

    /**
     * @param company the company to set
     */

    public void setCompany(Set<Company> company) {
        this.company = company;
    }




}

请有人帮帮我。或者如何将此 nativeQuery 转换为 Hibernate sql?谢谢

【问题讨论】:

    标签: sql hibernate jsp spring-boot spring-data-jpa


    【解决方案1】:

    在你的 JPA 存储库中试试这个

    @Query("Select c from Company c where c.industry.id = :id")
    List<Company> findJoin(@Param("id") long id);
    

    PS:尚未对此进行测试,但鉴于您的映射是正确的,它应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-04
      • 2015-02-27
      • 1970-01-01
      • 2015-07-01
      • 2021-09-06
      • 1970-01-01
      • 2015-08-03
      相关资源
      最近更新 更多