升級到彈簧引導版本1.3.0.RELEASE後,嘗試啓動時發現以下失敗。彈簧引導1.3.0升級和JPA自定義方法不起作用
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'productRepository': Invocation of init
method failed; nested exception is
org.springframework.data.mapping.PropertyReferenceException: No
property true found for type boolean! Traversed path: Product.active.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
... 64 more Caused by: org.springframework.data.mapping.PropertyReferenceException: No property true found for type boolean! Traversed path: Product.active.
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
以下是導致問題的代碼的相關代碼片段。沒有更改任何存儲庫或數據模型。
public interface ProductRepository extends JpaRepository<Product, Long> {
List<Product> findByActiveTrue_productInfoActiveTrue();
}
@Entity
@DiscriminatorValue(value = "0")
public class Product extends BaseProduct {
public boolean isSpecial() {
return special;
}
public void setSpecial(boolean special) {
this.special = special;
}
}
@Entity(name = "products")
@DiscriminatorColumn(name = "matchtype", discriminatorType = DiscriminatorType.INTEGER)
public abstract class BaseProduct implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "isspecial")
protected boolean special;
@Id
@GeneratedValue
@Column(name = "productid")
private Long productId;
@Column(name = "active")
private boolean active;
@OneToMany(mappedBy = "productId", fetch = FetchType.EAGER)
private Set<ProductInfo> productInfo;
@Entity(name = "products_ranges")
public static class ProductInfo {
@Id
@Column(name = "prodrangeid")
private Long id;
@Column(name = "product_id")
private Long productId;
@Column(name = "active")
private boolean active;
}
任何有關這個問題的幫助將不勝感激。我試着回到spring-data-common的舊版本,但是這並不適用於新的spring-data-jpa。
謝謝!
調試進一步,它似乎應該剝離「真/假」的代碼沒有這樣做。令人費解的是,沒有人報告過這個問題,因爲這會影響每個有布爾回購方法的人。它從方法的末尾剝去「真」,但不從其他第一次出現。這是發生了什麼 - ActiveTrue_productInfoActiveTrue => ActiveTrue_productInfoActive相反,它應該導致此Active_productInfoActive – slad