I am getting started to use Spring Data Elasticsearch. I read:
One of the attributes of the class needs to be an id, either by annotating it with @Id or using one of the automatically found names id or documentId.
but when I marked my Project entity field projectId with @Id then elasticsearch still is saying:
No id property found for class com.example.domain.entity.Project!
I figured out that I am using annotation @Id from JPA package: javax.persistence.Id
. When I add another @Id annotation @org.springframework.data.annotation.Id
for my field then fetching from repository is working!
The issue is that I do not want to use 2 kind of @Id annotation at the same time. Moreover, I would like to use JPA annotation only because of other module is using JPA based repository layer (Spring Data JPA).
Does Spring Data Elasticsearch supports @Id annotation from JPA? It is very important to know because further what about embedded id? Does @EmbeddedId annotation is supported by Spring Data Elasticsearch?
My entity:
@Entity
@Document(indexName = "project_list", type = "external")
public class Project implements Serializable {
@Id
@org.springframework.data.annotation.Id <-- without it Spring Data Elasticsearch is complaining that 'No id property found'
@Column(name = "PROJECT_ID")
private Long projectId;
.... other fields and getters/setters
}