我已经下文称各种消息来源,但我的问题仍然没有解决自定义方法, 自定义库找不到春天的数据JPA
public interface BaseRepositoryCustom<ContactDTO,Long> {
List<ContactDTO> getTestData(String name);
}
默认地将Impl
public class BaseRepositoryImpl implements BaseRepositoryCustom {
@PersistenceContext
private EntityManager entityManager;
@Override
public List<ContactDTO> getTestData(String name) {
List<ContactDTO> contact = entityManager.createQuery("select * from COM_CONTACT").getResultList();
System.out.println(contact.size());
return null;
}
主要仓库
public interface ConContactRepository extends JpaRepository<Contact, Long>,BaseRepositoryCustom {
List<ComContact> getTestData(String name);
}
我将得到DTO的列表作为我的结果我的主要版本库是哪里圆通型,我怎么能解决这个问题 异常
... 18 common frames omitted
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property getTestData found for type ComContact!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241)
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76)
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:235)
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373)
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:353)
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:84)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:61)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:94)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:205)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:72)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:369)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:192)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:239)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:225)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 28 common frames omitted
联系DTO
public class ContactDTO {
private String serviceName;
private String contactName;
private String title;
}
联系域模型
@Entity
@Table(name = "COM_CONTACT", schema = "JMS_SCHEMA")
public class ComContact implements java.io.Serializable {
private long id;
private String serviceNm;
private String contactNm;
private String title;
private long fkTemplateId;
private Character mailFlag;
private String mailAddress;
private Character faxFlag;
private String faxNr;
}
'ContactDTO'不是一个实体,而是你的结果返回'entity'对象,所以你需要'Entity_To_bean'的结果 –
变换,这是非常令人困惑。在'ConContactRepository'中,您使用'Contact'作为JpaRepository的实体类型,'BaseRepositoryCustom'中使用'ContactDTO',并且使用'ComContact'作为方法的返回类型。你应该决定,你想在你的版本库中使用哪种类型(并且它只应该是其中的一种)。 – dunni
除了上面的评论,我鼓励你不要对非getter方法使用'get'预处理方法。只要以其他方式来命名。 –