我試圖從表訪問者Postgresql數據庫獲取行。但我不需要所有列,但此刻執行自定義查詢,它不起作用。創建自定義查詢以獲取Hibernate中的特定列
EntityManager em = emf.createEntityManager();
Query query = em.createQuery("SELECT visitor_id, first_name, last_name, email, company, country_id FROM Visitor", Visitor.class);
List<Visitor> result = query.getResultList();
return result;
的錯誤控制檯顯示我是:
org.hibernate.exception.SQLGrammarException:無法執行查詢 org.postgresql.util.PSQLException:列名城市沒有被發現在 這個ResultSet。
SELECT visitor_id, city, company, email, email_confirmed, first_name,
identification_number, identification_other, image, is_active,
job_title, last_name, mobile_number, password, phone_number,
province, country_id, created_by, identification_type_id
FROM visitor;
所有列在那裏。所以我所做的就是調用函數來獲取所有行並將其設置爲另一個名爲bindRegisterToDashboard();的函數。它的功能只將表中的六列設置爲對象visitorDashBoardViewModel,以在視圖上顯示它。
//service file code
for (Visitor item: getVisitors()) {
visitorDashBoardViewModel.add(bindRegisterToDashboard(item);
}
return visitorDashBoardViewModel;
訪客模式:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long visitorId;
private String identificationOther;
private long identificationNumber;
private String firstName;
private String lastName;
private String email;
private boolean emailConfirmed;
private String phoneNumber;
private String mobileNumber;
private String password;
private String province;
private String city;
private String company;
private String jobTitle;
private Boolean isActive;
private byte[] image;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name="identification_type_id")
private IdentificationType identificationType;
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)
@JoinColumn(name = "country_id", nullable = false)
private Country country= new Country();
喜天使。你可以 - > \ d + tablename或者描述表格列請+從輸出看起來它沒有失敗的功能。 「從髖關節」猜測我會說你的操作結果集。 – pnorton
我編輯了quesion。謝謝。 –