我试图通过id从数据库中删除行。当我执行DELETE localhost:8080 / id(使用postman)时,我得到sql异常:org.postgresql.util.PSQLException:错误:列“deleted_at”的类型为bigint,但表达式的类型为timestamp with time zone
我的RequestMapping看起来像:
@RequestMapping (value = "/{id}", method = RequestMethod.DELETE)
public String delete (@PathVariable Long id){
Class class = classRepository.findOne(id);
class.setDeletedAt(System.currentTimeMillis()/1000);
classRepository.delete(class);
return "\"OK\"";
}
实体:
@Entity
@SQLDelete(sql = "UPDATE class SET deleted_at = now() where id = ?")
@Where(clause="deleted_at is NULL")
public class Class extends SoftDeleteableEntity {
private String name;
private String address;
// setters and getters
}
SoftDelete:
public abstract class SoftDeleteableEntity extends BaseEntity {
protected Long deletedAt;
// setters and getters
}
BaseEntity:
@MappedSuperclass
public abstract class BaseEntity implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
public void setId(Long id) {
this.id = id;
}
}
Class Repository接口扩展了JpaRepository,没有代码和@Component注释。 ClassService类的@Service注释只有@Autowires存储库。
我尝试过使用classRepository.save(class)而不是删除但是我无法将数据保存到数据库中。
我一直在论坛上寻找解决方案但似乎无法找到解决方案。任何帮助或提示将不胜感激。
P.S。我是编程新手(学习弹簧2周),如果我错过了stackoverflow上的一些现有答案或者问错了方法,我很抱歉。