I am trying to soft delete row from a database by id. When I do DELETE localhost:8080/id (using postman) I get sql exception: org.postgresql.util.PSQLException: ERROR: column "deleted_at" is of type bigint but expression is of type timestamp with time zone
My RequestMapping looks like:
@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:
@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 interface extends JpaRepository with no code and @Component annotation. ClassService class is with @Service annotation that only @Autowires repository.
I have tried using classRepository.save(class) instead of delete but then i can't get the data to be saved to database.
I have been searching the forums for a solution but can't seem to find one. Any help or tips would be appreciated.
P.S. I'm new to programming (learning spring for 2 weeks) and I'm sorry if I have missed some existing answer on stackoverflow or asked something the wrong way.