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

时间:2017-05-14 22:40:34

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

异常文本说“没有为类型找到属性fid”(原文如此!),我试图谷歌但却没有得到任何东西。可能它代表“功能ID”,但我不知道它是怎么回事。我如何解决它?我班上有什么问题吗?

我的属性类:

@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接口:

public interface AttributeRepository extends JpaRepository<Attribute, Integer > {

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

我的AttributeService接口:

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);
    }
}

我的例外:

    <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

1 个答案:

答案 0 :(得分:1)

你在这一行有一个错字:

List<Attribute> fidByObjectType(ObjectType objectType);

应该是

List<Attribute> findByObjectType(ObjectType objectType);

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