Repository always needs an ID column
See original GitHub issueI’m getting the following error while running a simple query with Predator JDBC and Postgress
error: Unable to implement Repository method: TaskRepository.findById(Object arg0). Cannot query entity [Task] on non-existent property: id error: Unable to implement Repository method: TaskRepository.existsById(Object arg0). Cannot query entity [Task] on non-existent property: id error: Unable to implement Repository method: TaskRepository.deleteById(Object arg0). Cannot query entity [Task] on non-existent property: id error: Unable to implement Repository method: TaskRepository.delete(Object arg0). Delete all not supported for entities with no ID error: Unable to implement Repository method: TaskRepository.delete(Object arg0). No possible implementations found.
Here is my Entity Class: ` @Entity @Data @NoArgsConstructor //@MappedEntity(namingStrategy = NamingStrategies.Raw.class) public class Task implements Serializable {
private static long serialVersionUID = 102843515;
@Id
@Column(name = "task_id")
@JsonProperty("task_id")
private Long taskId;
@Column(name = "assigned_workcenter")
@JsonProperty("assigned_workcenter")
@NotNull(message = "workcenter cannot be null")
private Integer assignedWorkcenter;
....
}`
Repositiry class:
` @JdbcRepository(dialect = Dialect.POSTGRES) public abstract class TaskRepository implements CrudRepository<Task, Long> {
private final JdbcOperations jdbcOperations;
public TaskRepository(JdbcOperations jdbcOperations) {
this.jdbcOperations = jdbcOperations;
}
@Transactional
public List<Task> findByTaskId(long taskId) {
String sql = "SELECT * FROM task AS task WHERE task.task_id = ?";
return jdbcOperations.prepareStatement(sql, statement -> {
statement.setLong(1, taskId);
ResultSet resultSet = statement.executeQuery();
return jdbcOperations.entityStream(resultSet, Task.class).collect(Collectors.toList());
});
}
} `
but if the table has the column name id
then it works fine.
Issue Analytics
- State:
- Created 4 years ago
- Comments:18 (5 by maintainers)
@graemerocher thank you for the response and you were spot on. i was using @Data annotation from Lombok, But when i added the Getter and Setter manually, the Repo is working. but unfortunately, with lombok @Data it’s not working.
Model:
Same here, got a Cannot query on ID with entity that has no ID error when using
@MappedEntity
+@Id
micronaut annotations on a Kotlin class, but works well usingjavax.persistence.*
annotations.