我想使用java / JEE中的注释从两个表创建视图, 因此,经过一些研究,我发现唯一的方法是使用 @Subselect 注释,所以我创建了3个实体 测试实体
@Table
@Entity
public class Test {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private String nom;
@Column
private String prenom;
@Column
private int age;
@Column
private String adresse;
@Column
private Date dateNaissance;
// getters and setters
}
竞争实体
@Entity
public class Compte {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private long solde;
@Column
private long numero;
@Column
private String description;
// getters and setters
}
而Compte_Test实体与视图具有相同的作用
@Entity
@Subselect("SELECT c2.id as idTest,c1.id as id,c1.solde as solde,c1.numero as numero, c2.nom as nom, c2.prenom as prenom FROM Compte c1 INNER JOIN Test c2 ON c1.id_test= c2.id")
@Synchronize({ "compte", "test" })
public class Compte_Test {
@Id
private long idCompte_Test;
@Column
private long idTest;
@Column
private long id;
@Column
private long solde;
@Column
private long numero;
@Column
private String nom;
@Column
private String prenom;
// getters and setters
}
我正在使用spring数据 @Query 注释从Compte_Test实体获取数据
@Query(value = "SELECT c from Compte_Test c ")
List<Compte_Test> fullTextSearch(Pageable pageable);
问题是它为我生成了一个错误
org.postgresql.util.PSQLException: ERROR: column compte_tes0_.id_compte_test does not exist
Position : 8
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) ~[postgresql-42.2.5.jar:42.2.5]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) ~[postgresql-42.2.5.jar:42.2.5]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) ~[postgresql-42.2.5.jar:42.2.5]