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

时间:2017-06-06 20:27:47

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

我的存储库中有nativeQuery Query。

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

但是,当我运行Page时,我有错误

无法提取ResultSet; 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?感谢

1 个答案:

答案 0 :(得分:1)

在您的JPA存储库中尝试此操作

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

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