1

I have that nativeQuery Query in my Repository.

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

But when i run the Page I have that error

could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract 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;

   }

Industry

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




}

Can somehone hlp me please. Or how to convert this nativeQuery to Hibernate sql? Thanks

1 Answer 1

1

Try this in your JPA repository

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

PS: Haven't tested this but it should work given that your mapping is correct.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.