JPA存储库无法正常工作

时间:2014-05-26 07:41:28

标签: jpa jpa-2.0 openjpa spring-data-jpa jpa-2.1

我是Open JPA的新手,我正在将我的应用程序数据库服务从JPA迁移到Hibernate作为供应商提供商,将OpenJPA作为供应商提供商迁移到JPA。一切都很好,但我无法迁移我的存储库。我收到以下错误:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property find found for
type com.entities.LevelPossibilityData
    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)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:271)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:245)
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:72)

这是我的实体:

package com.entities;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import java.lang.reflect.Field;

@Entity
@Table(name = "LEVEL_POSSIBILITY_DATA", schema = "DEV")
@NamedQueries({
    @NamedQuery(name = "LevelPossibilityData.findAllPossibilityGenIds", query = "SELECT distinct possibilityData.levelPossibilityGenId FROM LevelPossibilityData possibilityData where possibilityData.userCode is not null and possibilityData.possibilityType=?1  order by possibilityData.levelPossibilityGenId asc")})

public class LevelPossibilityData implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name = "LEVEL_SEQ_ID")
private BigDecimal levelSeqId;

@Column(name = "LEVEL_USER_CODE")
private String userCode;

@Column(name = "LEVEL_USER_POSSIBILITY_TYPE")
private String possibilityType;

@Column(name = "LEVEL_POSSIBILITY_GENERATOR_ID")
private String levelPossibilityGenId;

}

和我的存储库:

package com.dao;

import java.io.Serializable;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import com.entities.LevelPossibilityData;

public interface LevelPossibilityDataRepository<ID extends Serializable> extends JpaRepository<LevelPossibilityData, Serializable> {

public List<LevelPossibilityData> findAllPossibilityGenIds(String possibilityType); 

}

你可以帮我纠正这个错误吗?

1 个答案:

答案 0 :(得分:0)

我能够通过从实体中删除命名查询来解决问题。我使用@Query注释直接将查询引入了Repository。

只有一个问题,如果您正在使用openJPA并尝试在Repository中使用@Query,请尝试使用所使用实体的完整路径,例如 使用&#34; com.entities.LevelPossibilityData&#34;而不是&#34; LevelPossibilityData&#34;在您的查询中,即您的查询应该是&#34;从com.entities.LevelPossibilityData level&#34;中选择级别。而不是&#34;从LevelPossibilityData级别选择级别&#34;。

我希望这个解释会有所帮助。感谢大家花时间在这上面。