spring-tools: Cant use compsite keys for domain id when extending JpaRepository

Describe the bug For Spring Boot Tools extension V1.50.0 on vscode) When creating a interface that extends JpaRepository, it will throw an error saying “Expected Domain ID type is 'java.lang.String’vscode-spring-boot(DOMAIN_ID_FOR_REPOSITORY)”. When I switch back to v1.49.0 the error is no longer there. bug

To Reproduce

  1. Create an entity with a composite key
  2. Create a repository interface that extends JpaRepository<T,ID>

Sample

package sample.entities;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "customer_account_relationship")
@IdClass(CustomerAccountId.class)
public class CustomerAccountRel implements Serializable, ErrorLoggable {

  @Id
  @NotNull
  @Size(max = 20)
  @Column(name = "acct_nbr", length = 20)
  private String acct_nbr;

  @Id
  @Size(max = 50)
  @Column(name = "customer_id", length = 50)
  private String customerId;

  @NotNull
  @Size(max = 5)
  @Column(name = "relation_code", length = 5)
  private String relation_code;

  public void setAcct_nbr(String acct_nbr) {
    this.acct_nbr = StringUtils.truncate(acct_nbr, 20);
  }

  public void setCustomerId(String customerId) {
    this.customerId = StringUtils.truncate(customerId, 50);
  }

  public void setRelation_code(String relation_code) {
    this.relation_code = StringUtils.truncate(relation_code, 5);
  }

  @Override
  public String getId() {
    return customerId + " - " + acct_nbr;
  }

}
package sample.entities;

import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CustomerAccountId implements Serializable {

  private String acct_nbr;
  private String customerId;
}
package sample.repositories;

import sample.entities.CustomerAccountId;
import sample.entities.CustomerAccountRel;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CustomerAccountRelRepository
    extends JpaRepository<CustomerAccountRel, CustomerAccountId> {

  public List<CustomerAccountRel> findByCustomerId(String customerId);
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Screenshot 2024-04-02 at 11 14 47 If this validation gives you issues please paste your domain class and repository implementations with the short description of the issue.

@neo7BF no problem at all! This validation is very flaky unfortunately. Don’t be shy to bring up any issues with this validation in the future even if they don’t turn out to be issues.

If your id is String in the NotificationEntity then I’d expect NotificationRepository extends JPARepository<Notification, String> rather than JPARepository<Notification, Long> - i think Long is underlined as expected… Or am I missing something?

I just downloaded sts but this problem continues to occur. image

latest version of Spring STS plugin for eclipse is still having this issue.

it gives error ‘Expected Domain ID type is ‘long’’

@huhu72 thanks for reporting this. While we are fixing the issue the workaround would be turning this validation off in the preferences/settings.