【发布时间】:2017-11-16 20:04:50
【问题描述】:
我对本机查询有疑问。我有以下实体:
@Entity
@NamedNativeQueries({
@NamedNativeQuery(name = ExampleEntity.Q.getTestQuery, query = "SELECT a.name as name FROM ExampleEntity a WHERE a.id = 5", resultSetMapping = "nameMapping")
})
@SqlResultSetMapping(
name = "nameMapping",
entities = @EntityResult(
entityClass = ExampleEntity.class,
fields = {
@FieldResult(name="name", column="name")
}))
@Table(name = "ExampleEntity")
public class ExampleEntity implements Serializable {
public static class Q {
public static final String getTestQuery = "getTestQuery";
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@Column(name = "id")
private Long id;
@Column(name = "name")
private String name;
@Column(name = "surname")
private String surname;
我正在尝试使用以下代码在我的@Service 中调用此查询:
Query qz = em.createNativeQuery(ExampleEntity.Q.getTestQuery, "nameMapping");
qz.getResultList();
返回错误:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
这只是一个简单的例子,但显示了我的问题。 非常感谢!
【问题讨论】:
-
请添加完整的堆栈跟踪。
-
service.test() 中的异常,原因 = 'org.hibernate.exception.SQLGrammarException: could not extract ResultSet' and exception = 'org.hibernate.exception.SQLGrammarException: could not extract ResultSet' javax .persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: 无法提取结果集
标签: hibernate jpa entitymanager