I'm getting Invocation of init method failed; nested exception is java.lang.IllegalArgumentException on Repository class method Invocation

huangapple go评论70阅读模式
英文:

I'm getting Invocation of init method failed; nested exception is java.lang.IllegalArgumentException on Repository class method Invocation

问题

我在启动服务时遇到了以下异常:

... org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名为'levelDetailsService'的bean时出错:通过字段'storeRepo'表示的不满足的依赖关系;嵌套异常是org.springframework.beans.factory.BeanCreationException: 创建名为'storeRepo'的bean时出错:调用init方法失败;嵌套异常是java.lang.IllegalArgumentException:验证方法public abstract java.util.List com.tcs.opt.promotion.masterservice.dao.repo.StoreRepo.getStoreList(java.lang.Integer,java.util.List,java.lang.Character)失败!...

这是我在服务层中调用存储库的方法:

List<Object[]> storeObjs=storeRepo.getStoreList(salesOrgId,storeRequestDTO.getClassId(),'Y');

在这里,salesOrgId是整数,storeRequestDTO.getClassId()是整数列表。

存储库类:

@Repository
public interface StoreRepo extends JpaRepository<StoreEntity, Integer> {
	

	@Query("select str.store_id,str.store_number,str.store_name,str.city,str.state from StoreEntity str left outer join master.promo_market_store pstr "
			+ "on str.store_id=pstr.store_id where str.salesOrgID=:salesOrgID and pstr.level_id in (:levelIdList) and str.activeF=:activeF")
	List<Object[]> getStoreList(@Param("salesOrgID") Integer salesOrgID,@Param("levelIdList") List<Integer> levelIdList,@Param("activeF") Character activeF);

}

实体类:

@Entity
@Table(name=MasterQueryConstants.STORE_TBL,schema=MasterQueryConstants.MASTER_SCHEMA)
public class StoreEntity implements Serializable{
	private static final long serialVersionUID = 1L;
	@Id
	@Column(name="store_id")
	private Integer storeId;
	@Column(name="sales_org_id")
	private Integer salesOrgID;
	@Column(name="store_number")
	private Integer storeNumber;
	@Column(name="store_name")
	private String storeName;
	@Column(name="store_description")
	private String storeDescription;
	@Column(name="active_f")
	private Character activeF;
	@Column(name="city")
	private String city;
	@Column(name="state")
	private String state;
	
	
	public Integer getStoreId() {
		return storeId;
	}
	public void setStoreId(Integer storeId) {
		this.storeId = storeId;
	}
	public Integer getSalesOrgID() {
		return salesOrgID;
	}
	public void setSalesOrgID(Integer salesOrgID) {
		this.salesOrgID = salesOrgID;
	}
	public Integer getStoreNumber() {
		return storeNumber;
	}
	public void setStoreNumber(Integer storeNumber) {
		this.storeNumber = storeNumber;
	}
	public String getStoreName() {
		return storeName;
	}
	public void setStoreName(String storeName) {
		this.storeName = storeName;
	}
	public String getStoreDescription() {
		return storeDescription;
	}
	public void setStoreDescription(String storeDescription) {
		this.storeDescription = storeDescription;
	}
	public Character getActiveF() {
		return activeF;
	}
	public void setActiveF(Character activeF) {
		this.activeF = activeF;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	
	public StoreEntity()
	{
		/**
		 * 默认构造函数
		 */
	}
}

请帮助我解决这个问题,

英文:

I'm getting following exception while starting my service

... org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'levelDetailsService': Unsatisfied dependency expressed through field 'storeRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'storeRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.tcs.opt.promotion.masterservice.dao.repo.StoreRepo.getStoreList(java.lang.Integer,java.util.List,java.lang.Character)! ...

This is my method call for repository in service layer

List&lt;Object[]&gt; storeObjs=storeRepo.getStoreList(salesOrgId,storeRequestDTO.getClassId(),&#39;Y&#39;);

Here salesOrgId is Integer, storeRequestDTO.getClassId() is List of Integer

Repo class

@Repository
public interface StoreRepo extends JpaRepository&lt;StoreEntity, Integer&gt; {
	

	@Query(&quot;select str.store_id,str.store_number,str.store_name,str.city,str.state from StoreEntity str left outer join master.promo_market_store pstr &quot;
			+ &quot;on str.store_id=pstr.store_id where str.salesOrgID=:salesOrgID and pstr.level_id in (:levelIdList) and str.activeF=:activeF&quot;)
	List&lt;Object[]&gt; getStoreList(@Param(&quot;salesOrgID&quot;) Integer salesOrgID,@Param(&quot;levelIdList&quot;) List&lt;Integer&gt; levelIdList,@Param(&quot;activeF&quot;) Character activeF);

}

Entity Class

@Entity
@Table(name=MasterQueryConstants.STORE_TBL,schema=MasterQueryConstants.MASTER_SCHEMA)
public class StoreEntity implements Serializable{
	private static final long serialVersionUID = 1L;
	@Id
	@Column(name=&quot;store_id&quot;)
	private Integer storeId;
	@Column(name=&quot;sales_org_id&quot;)
	private Integer salesOrgID;
	@Column(name=&quot;store_number&quot;)
	private Integer storeNumber;
	@Column(name=&quot;store_name&quot;)
	private String storeName;
	@Column(name=&quot;store_description&quot;)
	private String storeDescription;
	@Column(name=&quot;active_f&quot;)
	private Character activeF;
	@Column(name=&quot;city&quot;)
	private String city;
	@Column(name=&quot;state&quot;)
	private String state;
	
	
	public Integer getStoreId() {
		return storeId;
	}
	public void setStoreId(Integer storeId) {
		this.storeId = storeId;
	}
	public Integer getSalesOrgID() {
		return salesOrgID;
	}
	public void setSalesOrgID(Integer salesOrgID) {
		this.salesOrgID = salesOrgID;
	}
	public Integer getStoreNumber() {
		return storeNumber;
	}
	public void setStoreNumber(Integer storeNumber) {
		this.storeNumber = storeNumber;
	}
	public String getStoreName() {
		return storeName;
	}
	public void setStoreName(String storeName) {
		this.storeName = storeName;
	}
	public String getStoreDescription() {
		return storeDescription;
	}
	public void setStoreDescription(String storeDescription) {
		this.storeDescription = storeDescription;
	}
	public Character getActiveF() {
		return activeF;
	}
	public void setActiveF(Character activeF) {
		this.activeF = activeF;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	
	public StoreEntity()
	{
		/**
		 * Default Constructor
		 */
	}
}

Please help me to resolve this issue,

答案1

得分: 1

这个错误表示@Query语法不正确。更详细的信息可能会在堆栈跟踪的下方出现,但在我看来,你可能在查询中混淆了列名和属性名。

你应该使用Java知道的属性名称,而不是查询中的列名。

所以,应该使用storeId而不是store_id,等等。

英文:

I'd say this error means that the @Query syntax is incorrect. Further details probably appear further down the stacktrace, but it looks to me like you have probably mixed up column names and property names in your query.

You should be using the property names as Java knows them, rather than the column name in your query.

So, storeId rather than store_id. etc

huangapple
  • 本文由 发表于 2020年8月7日 16:23:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/63298026.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定