无法提取ResultSet; SQL [n/a];嵌套的异常是org.hibernate.exception.SQLGrammarException:无法提取ResultSet
问题描述:
我的存储库中有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?由于
答
试试这个在您的JPA库
@Query("Select c from Company c where c.industry.id = :id")
List<Company> findJoin(@Param("id") long id);
PS:没有测试过这一点,但它应该工作给你的映射是正确的。