我想加入3張表以獲得所需的信息,使用entityManager.createQuery
。如何從JPA EntityManager中獲取返回的對象作爲自定義bean
代碼littlepet如下:
List<Object[]> o=entityManager.createQuery("SELECT u.loginId,ui.emailId,u.userId,ui.firstName,up.password,ui.phoneNunber,u.roleTypeId" + " From Users as u,UserInfo ui, UserPassword as up where u.userId = up.userId " + "AND u.userId=ui.userId").getResultList();
我有與上述返回的字段UserDetails
的bean。
public class UserDetails
{
String LoginId;
String Email;
String UserId;
String FirstName;
String Password;
String Mobile;
String RoleTypeId;
int Status;
getters() & setters()
}
但當我試圖使用,而不是List
的Object[]
List
UserDetails
它說ClassCastException
。
如何使用自定義bean獲取/轉換返回的對象?
嗯,我不知道答案,但使用聯接不是更好嗎? – niceman