Ich habe mir für MySQL Datenbank eine NestedSet - Table erstellt:
und dem Repository
erhalte ich eine Compilermeldung:
Weis einer was hier gerade schief läuft???
Code:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
@Entity
public class NestedSet {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Min(1)
@Column(name="lft")
private Long left = 1L;
@NotNull
@Min(2)
@Column(name="rgt")
private Long right = 2L;
public NestedSet() {
super();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getLeft() {
return left;
}
public void setLeft(Long left) {
this.left = left;
}
public Long getRight() {
return right;
}
public void setRight(Long right) {
this.right = right;
}
/**
* count the child for this entry
*
* @return Long
*/
public Long countChilds() {
return (this.right - this.left - 1) / 2;
}
/**
* has this entry childrens
*
* @return boolean
*/
public boolean hasChilds() {
return (this.right - this.left) == 1;
}
@Override
public String toString() {
return "NestedSet [id=" + id + ", left=" + left + ", right=" + right + ", countChilds()=" + countChilds()
+ ", hasChilds()=" + hasChilds() + "]";
}
}
und dem Repository
Code:
@Repository
public interface NestedSetRepository extends CrudRepository<NestedSet, Long> {
@Query("SELECT ns FROM NestedSet ns WHERE ns.left > ?1 AND ns.right < ?2")
List<NestedSet> getChilds(Long left, Long right);
@Query("UPDATE NestedSet SET right=right+2 WHERE right >= ?1")
void extendNestedSet(Long right);
}
erhalte ich eine Compilermeldung:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: right near line 1, column 70 [UPDATE com.nestedset.entities.NestedSet SET right=right+2 WHERE right >= ?1]
Weis einer was hier gerade schief läuft???