Repository navigation
Closed
Labels
for: eclipsesomething that is specific for Eclipsefor: vscodesomething that is specific for VSCodetheme: validationtype: bug
Milestone
Description
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.
To Reproduce
- Create an entity with a composite key
- 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);
}
Metadata
Metadata
Assignees
Labels
for: eclipsesomething that is specific for Eclipsefor: vscodesomething that is specific for VSCodetheme: validationtype: bug
Activity
BoykoAlex commentedon Nov 3, 2023
@huhu72 thanks for reporting this. While we are fixing the issue the workaround would be turning this validation off in the preferences/settings.
BoykoAlex commentedon Nov 3, 2023
Should be fixed with b1e1bf7
chalikir commentedon Dec 14, 2023
latest version of Spring STS plugin for eclipse is still having this issue.
it gives error 'Expected Domain ID type is 'long''
BoykoAlex commentedon Dec 14, 2023
Is the code snippet to reproduce the issue still the same? If not, do you mind pasting the java code snippets for which you still observe the issue?
2 remaining items
chalikir commentedon Dec 15, 2023
SajidhKareem commentedon Jan 7, 2024
Is this issue fixed? Right now I'm having this issue in my version of STS. Would like to know if a newer version has arrived with a fix.
BoykoAlex commentedon Jan 7, 2024
@SajidhKareem All fixes were put into STS 4.21.0 if this is the version you're using and still seeing issues then please raise a new issue for it.
As a workaround you can disable the validation for entity keys... it is somewhat experimental.
Go to Settings -> Spring -> Validation -> Boot 2.x Best Practices page. Find "Invalid Domain ID Type for Spring Data Repository" and switch it to "IGNORE" using the drop down.
neo7BF commentedon Feb 7, 2024
I just downloaded sts but this problem continues to occur.

BoykoAlex commentedon Feb 7, 2024
@neo7BF Can you paste your
NotificatioEntityin here please? You can simply disable this validation in the preferences as a workaround (Spring -> Validations)neo7BF commentedon Feb 21, 2024
This is the entity:
BoykoAlex commentedon Feb 21, 2024
If your id is
Stringin theNotificationEntitythen I'd expectNotificationRepository extends JPARepository<Notification, String>rather thanJPARepository<Notification, Long>- i thinkLongis underlined as expected... Or am I missing something?neo7BF commentedon Feb 23, 2024
Yes correct. I was misled by the fact that I had downloaded sources
and I had worked on it in another editor and it didn't highlight it to me as a compilation error as happens in STS. Assuming that the source was correct because it compiled from there, I thought it was a problem with STS, but instead it was a lack of the other editor.
I am sorry !
BoykoAlex commentedon Feb 23, 2024
@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.
WeiMao33 commentedon Apr 2, 2024
Sorry, I can't find the Boot 2.x Best Practices page. this is my screen shot.
ENV:
eclipse Version: 2023-12 (4.30.0)
BoykoAlex commentedon Apr 2, 2024
If this validation gives you issues please paste your domain class and repository implementations with the short description of the issue.
WeiMao33 commentedon Apr 3, 2024
thanks @BoykoAlex

here are the codes.
BoykoAlex commentedon Apr 3, 2024
Last comment extracted in #1220