Here is how I'm getting my User beans from Database.
session.createCriteria(User.class).list();
That returns all of User records from database. Interesting part is that, I don't want to get the password field from DB. Just want to exclude that field while retrieving.
Options I have
1) using projections on other fields. That needs to be more code to add in to projections list. So dropped from that idea.
2) With Sql I need to write a manually query, which kills the theme of Hibernate.
Any possibility to exclude a column value of Bean ?
you can try:
Reference :-
Let's assume that following is your POJO:
User.java
Now suppose you want to get only
id
&fName
fields and notlName
.Apart from the two approaches you've described, there's also a third way to achieve this, which uses HQL.
Modify User.java to have another constructor as follows:
In short, whatever fields you want to retrieve, you can list them in the constructor as well as in the query.
Hope this helps.