我想获取A表JOIN B表的值,但是我得到了SQLGrammarException:无法提取结果集

时间:2016-03-31 14:06:18

标签: java hibernate postgresql jpa

我使用PostGreSQL DB,它有两个表:

1.UserHeader ( userid integer primary key default nextval('userheader_seq'), username character varying(20) NOT NULL ) 2.TestTable ( testid integer NOT NULL, testnam character varying(20) NOT NULL, CONSTRAINT pk_testtable PRIMARY KEY (testid) )

我的两个实体:

@Entity
public class UserHeader implements Serializable {
@Id
@GeneratedValue(generator = "userHeader_seq")
@SequenceGenerator(name = "userHeader_seq", sequenceName = "userHeader_seq", allocationSize = 1)
private Integer userID;
private String userName = "";

@OneToMany(cascade=CascadeType.ALL)
private List<TestTable> testTables;

public List<TestTable> getTestTable() {
    return testTables;
}

public void setTestTable(List<TestTable> testTables) {
    this.testTables = testTables;
}


public Integer getUserID() {
    return userID;
}

public void setUserID(Integer userID) {
    this.userID = userID;
}

public String getUserName() {
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}

}

@Entity
public class TestTable implements Serializable {
@Id
private Integer testID;
private String testNam;

@ManyToOne(cascade=CascadeType.ALL)
private UserHeader userHeader;

public UserHeader getUserHeader() {
    return userHeader;
}

public void setUserHeader(UserHeader userHeader) {
    this.userHeader = userHeader;
}

public Integer getTestID() {
    return testID;
}

public void setTestID(Integer testID) {
    this.testID = testID;
}

public String getTestNam() {
    return testNam;
}

public void setTestNam(String testNam) {
    this.testNam = testNam;
}

}

我跑了:

Query query = entityManager.createQuery("from UserHeader u left join u.testTables t"); userHeaders = (List<Object[]>) query.getResultList();


但我得到例外:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet

我跑了:
Query query = entityManager.createQuery("from UserHeader u left join u.testTables t"); userHeaders = (List<Object[]>) query.getResultList();
但是我得到了例外: org.hibernate.exception.SQLGrammarException: could not extract ResultSet

有人能告诉我这是一个错误吗? 我的英语不好,请原谅我。

0 个答案:

没有答案