[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

Is it possible to select only specific fields from a table using Hibernate?

I have a table with a CLOB field. In certain cases when I do a select on the table using Hibernate, I don't want to get the CLOB data (for performance reasons).

Would there be a way to select data into an object while not populating certain fields in the object using Hibernate?
0
ashima_mahajan
Asked:
ashima_mahajan
  • 3
  • 3
1 Solution
 
Gibu GeorgeCTOCommented:
Use hql and specify the required columns only.
0
 
ashima_mahajanAuthor Commented:
Hey gibu_george,

Thanks for the prompt reply. Thats exactly what I am doing, but now I am getting a ClassCastException on the syso.  Which shouldn't be happening.

final List<Layout> layouts = getHibernateTemplate().find(
"select layout.primaryKey, layout.name, layout.type, layout.user,from Layout layout");
 
System.out.println(layouts.get(0).primaryKey.id);

Open in new window

0
 
objectsCommented:
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Gibu GeorgeCTOCommented:
I think objects has given you a better solution(I didn't know that properties can be lazy fetched, I thought it is for associations in hibernate 3.0), use lazy fetching to fetch  the CLOB, only when you gall the getter method it will actually be fetched.

I am not sure why class cast exception is coming, can you put the hole stack trace the mapping xml for this particular class.
0
 
Gibu GeorgeCTOCommented:
I thought it is for associations only
0
 
ashima_mahajanAuthor Commented:
What do u guys think about scalar queries?
0
 
ashima_mahajanAuthor Commented:
Thanks objects. I used a scalar query but I got the idea from your link.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now