-->
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.  [ 4 posts ] 
Author Message
 Post subject: createQuery vs createCriteria
PostPosted: Wed Nov 16, 2005 11:40 am 
Beginner
Beginner

Joined: Fri Sep 24, 2004 8:18 am
Posts: 24
Hi,

I have the following criteria :
Code:
List list = hibernateSession.createCriteria(A.class)
                            .createAlias("pojo2","e")
                            .setProjection( Projections.projectionList()
                                .add( Projections.property("e.col1").as("Description") )
                                .add( Projections.property("this.cola").as("Comments") )
                            )
                            .add( Property.forName("e.col2").eq( anId ) )
                            .addOrder( Order.asc("e.col3") )
                            .setCacheable(true)
                            .setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
                            .list();

What will be the syntax if I use an entityManager.createQuery() ?
I mean, how to convert the above if I want to use entityManager ?

Thanks for any help/suggestions/pointers.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 8:32 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you can access the underlying session when working with a em ( (HibernateentityManager) em ).getSession() and then still use the criteria API

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 12:47 pm 
Beginner
Beginner

Joined: Fri Sep 24, 2004 8:18 am
Posts: 24
emmanuel wrote:
you can access the underlying session when working with a em ( (HibernateentityManager) em ).getSession() and then still use the criteria API

Oh la vache ... merci Manu ... :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 4:00 pm 
Beginner
Beginner

Joined: Wed Feb 08, 2006 5:45 pm
Posts: 23
Location: Phoenix, AZ
I'm curious, if the only kind of querying being done is by Criteria, are there any advantages to using the EntityManager as all I will be doing with it is opening a regular Session?

Thanks,
Ben


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.