In my JPA2/Hibernate application I have table USERS and matching entity User + DAO.
Now, I created view V_USERS, which contains filtered data from table USERS.
Can I reuse entity User to query data from this view ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No you can’t. You can map two different classes into the same table but not the other way around.
The reason for this limitation is simple, how would JPA provider knew which table do you have in mind in the following query:
However you might want to create a base class
AbstractUserwith all properties and have to empty subclasses:Userand for instanceVUser. The latter two classes will have a mapping to different tables/views. See MappedSuperclass and an example there.