We are facing a problem creating some JPA repository methods following the naming conventions of JPA. Our entity is
@Entity(name = "regcmp_document")
@Table(name = "regcmp_document")
@NamedQuery(name = "RegcmpDocument.findAll", query = "SELECT r FROM regcmp_document r")
public class RegcmpDocument implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "i_regcmpdoc_id")
private Long iRegcmpdocId;
@Column(name = "i_regsec_id")
private String iRegsecId;
public Long getIRegcmpdocId() {
return this.iRegcmpdocId;
}
public void setIRegcmpdocId(Long iRegcmpdocId) {
this.iRegcmpdocId = iRegcmpdocId;
}
public String getIRegsecId() {
return this.iRegsecId;
}
public void setIRegsecId(String iRegsecId) {
this.iRegsecId = iRegsecId;
}
}
and the repository we are trying to create is
@Repository
public interface RegcmpDocumentRepository extends JpaRepository<RegcmpDocument, Long> {
RegcmpDocument findByiRegcmpdocIdAndIRegsecId(Long regcmpdocId, String iRegsecId);
}
The problem is that all columns, including these two, as well all attributes in our project are generated though automated tool that gave them these kind of names (following database column names). The error that we get after jpa validation is
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [IRegsecId] on this ManagedType [gr.neurosoft.factoring.entities.RegcmpDocument]
at org.hibernate.metamodel.model.domain.internal.AbstractManagedType.checkNotNull(AbstractManagedType.java:147)
at org.hibernate.metamodel.model.domain.internal.AbstractManagedType.getAttribute(AbstractManagedType.java:118)
at org.hibernate.metamodel.model.domain.internal.AbstractManagedType.getAttribute(AbstractManagedType.java:43)
at org.springframework.data.jpa.repository.query.QueryUtils.toExpressionRecursively(QueryUtils.java:635)
at org.springframework.data.jpa.repository.query.QueryUtils.toExpressionRecursively(QueryUtils.java:619)
at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.getTypedPath(JpaQueryCreator.java:385)
at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.build(JpaQueryCreator.java:308)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.toPredicate(JpaQueryCreator.java:211)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.and(JpaQueryCreator.java:133)
at org.springframework.data.jpa.repository.query.JpaQueryCreator.and(JpaQueryCreator.java:59)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:122)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:95)
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:81)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.<init>(PartTreeJpaQuery.java:217)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$CountQueryPreparer.<init>(PartTreeJpaQuery.java:348)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:91)
After some investigation I realized that the decapitalize of Java.Bean.Introspector is used and when two first letters of an attribute are uppercase then it returns name as is.
My question is if we can override somehow this method and hint JPA to use a custom one? If not ,can we configure jpa to handle this columns differently?
Thanks a lot for your help