2017-06-06 1345 views
0

我的存儲庫中有nativeQuery Query。無法提取ResultSet; SQL [n/a];嵌套的異常是org.hibernate.exception.SQLGrammarException:無法提取ResultSet

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

但是當我運行頁面我有錯誤

不能提取的ResultSet; SQL [n/a];嵌套的例外是 org.hibernate.exception.SQLGrammarException:無法提取 的ResultSet

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; 
    } 




} 

能somehone HLP我請。或者如何將這個nativeQuery轉換爲Hibernate sql?由於

回答

0

試試這個在您的JPA庫

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

PS:沒有測試過這一點,但它應該工作給你的映射是正確的。

相關問題