Also mache ich eine Projektion für eine Entität namens CodeCenterApplications. Sehen Sie sich die Einheit unterProjektionsfehler mit Feder-Einheit
@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;
}
}
Der Vorsprung ist wie folgt, wie Sie ich nur den Namen
public interface NameOnly {
String getName();
}
Schließlich
wollen sehen, hier ist die Methode im Repository, das es/**
* 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);
verwendet
Wenn ich jedoch versuche, diese Repository-Methode aufzurufen, erhalte ich den folgenden Fehler
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"])
Ich merke es nicht erkennen, dass getName() soll sich auf die Entität beziehen, aber stattdessen denkt es versucht, das Attribut einer Zeichenfolge zu bekommen.
Auch dies ist meine erste Frage, also ist Kritik willkommen.