当我尝试在下面实现query
时,我收到以下错误:
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token
我的查询位于扩展PersonRepository
CrudRepository
中
查询:
@Modifying
@Transactional
@Query("DELETE (entity) FROM Person entity WHERE entity.id = :id")
List<Person> deleteFromPersonWithId(@Param("id") String id);
我的语法错误是什么?
答案 0 :(得分:1)
你没有正确的DELETE查询语法,它应该是这样的。
DELETE FROM Person entity WHERE entity.id = :id
顺便说一下,有一个delete方法可以完全按照CrudRepository
本身的方式执行。所以不需要复制它。
答案 1 :(得分:0)
查询必须是:
<!doctype html>
<head>
<meta charset="utf-8">
<!---- >
<base href="https://polygit.org/components/">
<!---- >
Toggle below/above as backup when server is down
<!---->
<base href="https://polygit2.appspot.com/components/">
<!---->
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link href="polymer/polymer.html" rel="import">
<link href="firebase-element/firebase-collection.html" rel="import">
<link href="paper-button/paper-button.html" rel="import">
</head>
<body>
<dom-module id="x-element">
<template>
<style></style>
<p>
<paper-button on-tap="_handleClick">Click Me</paper-button>
</p>
<!---->
<firebase-collection
location="https://dinosaur-facts.firebaseio.com/dinosaurs"
data="{{dinosaurs}}"></firebase-collection>
<template is="dom-repeat" items="[[dinosaurs]]" as="dinosaur">
Hello, world
</template>
<!---->
Hello, world
</template>
<script>
(function(){
Polymer({
is: "x-element",
_handleClick: function() {
console.log('You clicked me!');
}
});
})();
</script>
</dom-module>
<x-element></x-element>
</body>
答案 2 :(得分:0)
entityManager.remove(entityInstance)
将在提交事务时从DB中删除实体。
答案 3 :(得分:0)
更改您的注释;
@Modifying
@Transactional
@Query("DELETE FROM Person WHERE id = :id")
void deleteFromPersonWithId(@Param("id") String id);