java - org.springframework.data.mapping.PropertyReferenceException 我需要更改什么?

标签 java spring hibernate spring-data spring-data-jpa

异常的文本显示“没有找到类型的属性 fid”(原文如此!),我尝试用谷歌搜索,但一无所获。可能它代表“功能 ID”,但我不确定它到底发生了什么。我如何解决它?我的类(class)有问题吗?

我的属性类:

@Entity
@Table(name = "LAB3_ATTRIBUTES")
public class Attribute {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "ATTR_ID", length = 10, nullable = false)
private Integer id;

@Column(name = "NAME")
private String name;

@ManyToOne
@JoinColumn(name = "OBJECT_TYPE_ID", referencedColumnName = "OBJECT_TYPE_ID")
private ObjectType objectType;

@OneToMany(mappedBy = "attribute", cascade = CascadeType.ALL)
private List<Parameter> parameters;

public Attribute() {
}

public Attribute(String name, ObjectType objectType) {
    this.name = name;
    this.objectType = objectType;
}

public Integer getId() {
    return id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public ObjectType getObjectType() {
    return objectType;
}

public void setObjectType(ObjectType objectType) {
    this.objectType = objectType;
}

public List<Parameter> getParameters() {
    return parameters;
}

public void setParameters(List<Parameter> parameters) {
    this.parameters = parameters;
}
}

我的AttributeRepository接口(interface):

public interface AttributeRepository extends JpaRepository<Attribute, Integer > {

    Attribute findById(int id);
    List<Attribute> findByName(String name);
    List<Attribute> fidByObjectType(ObjectType objectType);
}

我的AttributeService接口(interface):

public interface AttributeService {
    void save(Attribute attribute);
    Attribute findById(int id);
    List<Attribute> findByName(String name);
    List<Attribute> findByObjectType(ObjectType objectType);
}

我的 AttributeServiceImpl 类:

@Service
public class AttributeServiceImpl implements AttributeService {

    @Autowired
    private AttributeRepository attributeRepository;    

    public void save(Attribute attribute) {
        attributeRepository.save(attribute);
    }
    public Attribute findById(int id) {
        return attributeRepository.findById(id);
    }
    public List<Attribute> findByName(String name) {
        return attributeRepository.findByName(name);
    }
    public List<Attribute> findByObjectType(ObjectType objectType) {
        return attributeRepository.fidByObjectType(objectType);
    }
}

我的异常(exception):

    <15 ìàÿ 2017, 8:49:22,550 AM EEST> <Error> <org.springframework.web.context.ContextLoader> <BEA-000000> <Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attributeServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.shop.database.repositories.AttributeRepository com.shop.database.services.impl.AttributeServiceImpl.attributeRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attributeRepository': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
    Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.shop.database.repositories.AttributeRepository com.shop.database.services.impl.AttributeServiceImpl.attributeRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attributeRepository': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:571)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attributeRepository': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1574)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:316)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
    Truncated. see log file for complete stacktrace
Caused By: org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute
    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:353)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
    Truncated. see log file for complete stacktrace
> 
<15 ìàÿ 2017, 8:49:22,561 AM EEST> <Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attributeServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.shop.database.repositories.AttributeRepository com.shop.database.services.impl.AttributeServiceImpl.attributeRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attributeRepository': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attributeServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.shop.database.repositories.AttributeRepository com.shop.database.services.impl.AttributeServiceImpl.attributeRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attributeRepository': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
    Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.shop.database.repositories.AttributeRepository com.shop.database.services.impl.AttributeServiceImpl.attributeRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attributeRepository': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:571)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'attributeRepository': FactoryBean threw exception on object creation; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1574)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:316)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
    Truncated. see log file for complete stacktrace
Caused By: org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute
    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:353)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
    Truncated. see log file for complete stacktrace
> 
<15 ìàÿ 2017, 8:49:22,608 AM EEST> <Warning> <EclipseLink> <BEA-2005000> <2017-05-15 08:49:22.592--No partition instance associated with current SessionManager instance.> 
<15 ìàÿ 2017, 8:49:22,614 AM EEST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "4217989485440" for task "0" on [partition-name: DOMAIN]. Error is: "weblogic.application.ModuleException: org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute"
weblogic.application.ModuleException: org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute
    at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
    at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:233)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:228)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
    Truncated. see log file for complete stacktrace
Caused By: org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute
    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:353)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
    Truncated. see log file for complete stacktrace
> 
<15 ìàÿ 2017, 8:49:22,618 AM EEST> <Error> <Deployer> <BEA-149202> <Encountered an exception while attempting to commit the 9 task for the application "packear_ear" on [partition-name: DOMAIN].> 
<15 ìàÿ 2017, 8:49:22,662 AM EEST> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application "packear_ear".> 
<15 ìàÿ 2017, 8:49:22,663 AM EEST> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException: org.springframework.data.mapping.PropertyReferenceException: No property fid found for type com.shop.database.entities.Attribute:org.springframework.data.mapping.PropertyReferenceException:No property fid found for type com.shop.database.entities.Attribute
    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:353)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
    Truncated. see log file for complete stacktrace

最佳答案

您在这行中有一个拼写错误:

List<Attribute> fidByObjectType(ObjectType objectType);

应该是

List<Attribute> findByObjectType(ObjectType objectType);

由于拼写错误,Spring Data 正在寻找名为“fid”的属性,该属性当然不存在。

关于java - org.springframework.data.mapping.PropertyReferenceException 我需要更改什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43969479/

相关文章:

java - adb 无法连接到位于 tcp :5037 的守护程序

java - 两个微服务之间的通信

java - 如何限制 Hibernate Envers 中的审计类型

java - 为什么循环会覆盖初始代码,而不是创建新的 XSSFSheet?

java - 如何在Android中创建 "clickable"行并在TextView中突出显示该行和文本

java - 我怎样才能将这个使用 SpringJUnit4ClassRunner 的面向 'spring 3.1' 的 junit4 测试转换为基于 spring 的基于 junit3.8 的测试?

java - Spring 安全许可证全部不起作用

hibernate - 是否可以在没有外键的情况下使用 Hibernate

java - 读取/更新时的 Hibernate 并发(?)问题

java - 使用 LWJGL 进行文本输入