2016-11-05 7 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()がエンティティを参照しているはずですが、代わりに文字列の属性を取得しようとしていると考えられます。

また、これは私の最初の質問ですので、批評を歓迎します。

答えて

0

Hibernateは、Javaオブジェクト(エンティティオブジェクト)をリレーショナルデータベースにマップするORMフレームワークであり、データベーステーブルにCodeCenterApplicationのすべてのプロパティ(名前、バージョンなど)をマップしませんでした。

アノテーションを使用しているとして、あなたは以下のようなデータベーステーブルの列にプロパティをマップするために@Columnを使用する必要があります。

@Column(name="YOUR_TABLE_COLUMN") 

protected String name; 

//other properties also need to be mapped including insertionDate 

あなたはhere

を見ることができます
関連する問題