These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How do I change fetch mode?
PostPosted: Fri Oct 22, 2010 9:26 am 
Newbie

Joined: Wed Jun 30, 2010 4:28 pm
Posts: 4
Spring/Hibernate
We are using annotations & AOP, not xml so we don't have and don't want a hibernate config xml.
I can't change the entities because they are auto generated from the database so I can't just tag the entity with @Fetch.

How can I change the fetch mode pragmatically? The select we are using contains no joins so I can't toss it in there that I know of. It looks like this. My HQL isn't very good:

select * from q where q.y = specifiedId

Clue? Is there an annotation I missed somewhere? Some snytax I can use to modify the above HQL?


Top
 Profile  
 
 Post subject: Re: How do I change fetch mode?
PostPosted: Fri Oct 22, 2010 12:26 pm 
Newbie

Joined: Wed Jun 30, 2010 4:28 pm
Posts: 4
Here is an example of another way one may use HQL to retrieve with eager fetch. In response to my own question, one may do this:

@Autowired
EntityManager em;
.
.
.
String id = "1234";
Query q = em.createQuery("select * from thingamajig t fetch all properties where t.id =: id");

q.setParameter(id);

Type thingamabob = (cast to what ever type) q.getSingleResult()


Top
 Profile  
 
 Post subject: Re: How do I change fetch mode?
PostPosted: Fri Oct 22, 2010 1:32 pm 
Newbie

Joined: Wed Jun 30, 2010 4:28 pm
Posts: 4
Looking at the above, there should be a way to use the entity manager instead of a query.

I should be able to:

/*
Some code here to set the fetch mode to eager
*/
SomeType thing = (cast to some type) em.find(thingamajig.class,someKindOfId);

Anyone know how this can be done? This would simplify a lot of our code.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.