Does Spring Data Elasticsearch support @Id annotation from JPA?

I started using Spring Data Elasticsearch. I read:

One of the class attributes must be an identifier, either by annotating it with @Id or using one of the automatically found id or documentId names.

but when I tagged the Project project projectId object with @Id, then elasticsearch still says:

No id property found for class com.example.domain.entity.Project!

      

I realized I was using the @Id annotation from the JPA: package javax.persistence.Id

. When I add another @Id comment @org.springframework.data.annotation.Id

for my field, then the checkout works!

The problem is that I don't want to use 2 kinds of @Id annotations at the same time. Moreover, I would like to use JPA annotation only because another module is using a JPA (Spring Data JPA) based repository layer.

Does Spring Data Elasticsearch support @Id annotation from JPA? This is very important to know, because then what about the inline id? Are @EmbeddedId annotations supported by Spring Data Elasticsearch?

My essence:

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

      

+4


source to share


2 answers


Yes, 1.3.0 supports @Id

, but you need a getter (maybe a bug?)

ElasticsearchTemplate.getPersistentEntityId

takes your entity, tries to find the @Id annotation, and then only returns id if a getter definition is defined.



However, it doesn't seem to support @EmbeddedId: SimpleElasticsearchPersistentProperty.SUPPORTED_ID_PROPERTY_NAMES

0


source


I have a similar problem, I am also using JPA and Elastic search and it resolved after changing

@Column(name = "PROJECT_ID")
    private Long projectId;

      

in



javax.persistence.Id;

      

default name for id column

@Column(name = "id")
    private Long id;

      

0


source







All Articles