question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repository always needs an ID column

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
Bonythomasvcommented, Jul 23, 2019

@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.

@JdbcRepository(dialect = Dialect.POSTGRES)
public interface  TaskRepository extends CrudRepository<Task, Long> {
}

Model:

public class Task implements Serializable {

    private static long serialVersionUID = 102843515;

    @Id
    @GeneratedValue
    private Long taskId;
    private String notes;


    public Long getTaskId() {
        return taskId;
    }

    public void setTaskId(Long taskId) {
        this.taskId = taskId;
    }

    public String getNotes() {
        return notes;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }



}```

1reaction
tdudouetcommented, Aug 9, 2019

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 using javax.persistence.* annotations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use spring Repository without @Id? - Stack Overflow
JPA requires that every entity has an ID. So no, entity w/o an ID is not allowed. Every JPA entity must have a...
Read more >
Spring Data JDBC - How to use custom ID generation
The database generates an ID, and the ID is set in the aggregate root ... ALWAYS: Oracle always generates a value for the...
Read more >
Returning an Auto-Generated Id with JPA - Baeldung
In this tutorial, we'll discuss how we can handle auto-generated ids with JPA.
Read more >
TypeORM - Amazing ORM for TypeScript and JavaScript (ES7 ...
To add database columns, you simply need to decorate an entity's properties you want to make into a column with a @Column decorator....
Read more >
Entities - typeorm - GitBook
@PrimaryColumn(). lastName: string. } When you save entities using save it always tries to find an entity in the database with the given...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found