2016-11-05 1 views
0

그래서 CodeCenterApplications라는 엔티티의 투영을하고 있습니다.스프링 엔티티를 사용한 프로젝션 오류

@Entity 
@Table(name = "CODE_CENTER_APPLICATIONS") 
public class CodeCenterApplication { 

    @Id 
    @Column(columnDefinition = "BIGINT") 
    protected Integer id; 
    protected String name; 
    protected String version; 
    @JsonFormat(pattern = "yyyy-MM-dd") 
    protected Date insertionDate; 


    @ManyToMany 
    @JoinTable(name = "APPROVALS", joinColumns = {@JoinColumn(name = "APPLICATION_ID", columnDefinition = "BIGINT")}, 
      inverseJoinColumns = {@JoinColumn(name = "API_ID")}) 
    private List<API> apis; 

    public CodeCenterApplication() { 
    } 

    public CodeCenterApplication(Integer id, String name, String version) { 
     this.id = id; 
     this.name = name; 
     this.version = version; 
    } 


    public CodeCenterApplication(Integer id, String name, String version, Date insertionDate) { 
     this.id = id; 
     this.name = name; 
     this.version = version; 
     this.insertionDate = insertionDate; 
    } 

    public List<API> getApis() { 
     return apis; 
    } 

    public void setApis(List<API> apis) { 
     this.apis = apis; 
    } 

    /** 
    * Can be used if you wish to generate a table with the appropriate headers. 
    * 
    * @return 
    */ 
    @JsonIgnore 
    public String[] getColumnNames() { 
     String[] header = {"NAME", "VERSION", "INSERTION_DATE"}; 
     return header; 
    } 

    /** 
    * A giant 'getter' for all all attributes save for id. 
    * 
    * @return 
    */ 
    @JsonIgnore 
    public String[] getAttributeList() { 
     String insertionDateString = "2016-01-01"; //insertionDate.toString(); 
     String[] attributeList = {name, version, insertionDateString}; 
     return attributeList; 
    } 

    public int getId() { 
     return id; 
    } 

    public void setId(Integer id) { 
     this.id = id; 
    } 

    public String getName() { 
     return name; 
    } 

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

    public String getVersion() { 
     return version; 
    } 

    public void setVersion(String version) { 
     this.version = version; 
    } 

    public Date getInsertionDate() { 
     return insertionDate; 
    } 

    public void setInsertionDate(Date insertionDate) { 
     this.insertionDate = insertionDate; 
    } 
} 

아래의 실체를 참조 투사 당신은 내가 이름 만 원하는 참조

마지막으로
public interface NameOnly { 

    String getName(); 
} 

, 여기를

/** 
* The following strings are used in creating queries. 
*/ 
String fuzzySchema = "\"FROODES2\""; 
String fuzzyTable = "\"APPLICATIONS\""; 
String fuzzyColumns = "\"NAME\""; 
String fuzzySearchInput = ":name"; 

String fuzzyGroupSearchString = "SELECT " + fuzzyColumns + " FROM " + fuzzySchema + "." + fuzzyTable 
      + " WHERE CONTAINS((" + fuzzyColumns + "), " + fuzzySearchInput + ", FUZZY(0.75)) GROUP BY " + 
      fuzzyColumns + ", SCORE()" + " ORDER BY " + "SCORE() " + "DESC " + "LIMIT :limit OFFSET :offset"; 


    @Query(value = fuzzyGroupSearchString, nativeQuery = true) 
    List<NameOnly> findByNameGrouped(@Param("name") String name, @Param("offset") int offset, @Param("limit") int 
      limit); 
를 사용하는 저장소의 방법입니다 수있는, 다음과 같다

그러나이 저장소 메서드를 호출하려고하면 다음 오류가 발생합니다.

org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: Invalid property 'name' of bean class [java.lang.String]: Could not find field for property during fallback access! (through reference chain: java.util.ArrayList[0]->$Proxy136["name"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid property 'name' of bean class [java.lang.String]: Could not find field for property during fallback access! (through reference chain: java.util.ArrayList[0]->$Proxy136["name"]) 

getName()이 엔티티를 참조하는 것으로 감지되지 않고, 대신 String의 속성을 가져 오는 것으로 생각됩니다.

또한 이것은 첫 번째 질문이기 때문에 비평을 환영합니다.

답변

0

Hibernate는 자바 객체 (Entity Object)를 관계형 데이터베이스로 매핑하는 ORM 프레임 워크이므로 데이터베이스 테이블에 CodeCenterApplication의 모든 속성 (이름, 버전 등)을 매핑하지 않았습니다. 당신은 here

볼 수 있습니다

@Column(name="YOUR_TABLE_COLUMN") 

protected String name; 

//other properties also need to be mapped including insertionDate 

을 : 당신이 주석을 사용하는 것처럼

, 당신은 다음과 같은 데이터베이스 테이블 컬럼 속성을 매핑 할 @Column를 사용할 필요가

관련 문제