You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Sreedhar.sirigiri" <sr...@gmail.com> on 2007/08/03 15:19:00 UTC

Equivalent class in OpenJPA.


Hi All,

We are porting our application from Hibernate to OpenJPA in the Database
tier. We faced performance problems while processing the JPQL queries.

here are the sample code snippets:

Hibernate:

//do something

Criteria criteria = session.createCriteria(GeneralConfigDTO.class);
criteria.add(Expression.eq("name", configName));
GeneralConfigDTO configDTO = (GeneralConfigDTO)criteria.uniqueResult();

//do something

OpenJPA:
//do something

Query query = session.createQuery("select model from GeneralConfigDTO model
where model.name = '"+configName+"'");
try{
  GeneralConfigDTO configDTO = (GeneralConfigDTO)query.getSingleResult();
}catch(NoResultException nre){
  configDTO = null;
}catch(NonUniqueResultException ure){
  configDTO = null;
}

//do something

We have around 21 tuples in the relation "GeneralConfigDTO".

The Hibernate code snippet is getting executed in around 20msecs, whereas,
OpenJPA code snippet is taking around 400msecs, which is accounting for
overall performance of the Application.

The reason why we went for JPQL is because, we didn't find an equivalent
Hibernate's "Criteria" class in OpenJPA. 

Any help would be highly appreciated.

Thanks in advance.

Sreedhar Sirigiri.



-- 
View this message in context: http://www.nabble.com/Equivalent-class-in-OpenJPA.-tf4212515.html#a11983221
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: Equivalent class in OpenJPA.

Posted by Patrick Linskey <pl...@gmail.com>.
Also, it'd be good to know more about where the cost is being
incurred. In particular, how fast are the query parses after the first
run?

-Patrick

On 8/3/07, Pinaki Poddar <pp...@bea.com> wrote:
> 1.
>  Try using named/positional parameters in JPQL.
>
>  Query query = session.createQuery("select model from GeneralConfigDTO
> model where model.name = ?cname");
>  query.setParameter("cname", configName);
>
>  or
>
>  Query query = session.createQuery("select model from GeneralConfigDTO
> model where model.name = :1"); // index starts from 1
>  query.setParameter(1, configName);
>
>  If the query being executed multiple times, binding parameters will
> save repeated query compilation.
>
> 2. It may be useful to post the exact SQL being used by Hibernate &
> OpenJPA.
>
>
> Pinaki Poddar
> 972.834.2865
>
> -----Original Message-----
> From: Sreedhar.sirigiri [mailto:sreedhar.sirigiri@gmail.com]
> Sent: Friday, August 03, 2007 8:22 AM
> To: dev@openjpa.apache.org
> Subject: Equivalent class in OpenJPA.
>
>
> Hi All,
>
> We are porting our application from Hibernate to OpenJPA in the Database
> tier. We faced performance problems while processing the JPQL queries.
>
> here are the sample code snippets:
>
> Hibernate:
>
> //do something
>
> Criteria criteria = session.createCriteria(GeneralConfigDTO.class);
> criteria.add(Expression.eq("name", configName)); GeneralConfigDTO
> configDTO = (GeneralConfigDTO)criteria.uniqueResult();
>
> //do something
>
> OpenJPA:
> //do something
>
> Query query = session.createQuery("select model from GeneralConfigDTO
> model where model.name = '"+configName+"'"); try{
>   GeneralConfigDTO configDTO =
> (GeneralConfigDTO)query.getSingleResult();
> }catch(NoResultException nre){
>   configDTO = null;
> }catch(NonUniqueResultException ure){
>   configDTO = null;
> }
>
> //do something
>
> We have around 21 tuples in the relation "GeneralConfigDTO".
>
> The Hibernate code snippet is getting executed in around 20msecs,
> whereas, OpenJPA code snippet is taking around 400msecs, which is
> accounting for overall performance of the Application.
>
> The reason why we went for JPQL is because, we didn't find an equivalent
> Hibernate's "Criteria" class in OpenJPA.
>
> Is there any configurations that we have to do to optimize JPQL queries.
>
> Is there any equivalent class for "Criteria" in OpenJPA.
>
> Any help would be highly appreciated.
>
> Thanks in advance.
>
> Sreedhar Sirigiri.
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Equivalent-class-in-OpenJPA.-tf4212515.html#a11983
> 221
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>
>
> Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.
>


-- 
Patrick Linskey
202 669 5907

RE: Equivalent class in OpenJPA.

Posted by Pinaki Poddar <pp...@bea.com>.
1. 
 Try using named/positional parameters in JPQL.
  
 Query query = session.createQuery("select model from GeneralConfigDTO
model where model.name = ?cname");
 query.setParameter("cname", configName);

 or

 Query query = session.createQuery("select model from GeneralConfigDTO
model where model.name = :1"); // index starts from 1
 query.setParameter(1, configName);

 If the query being executed multiple times, binding parameters will
save repeated query compilation.
 
2. It may be useful to post the exact SQL being used by Hibernate &
OpenJPA.
  

Pinaki Poddar
972.834.2865

-----Original Message-----
From: Sreedhar.sirigiri [mailto:sreedhar.sirigiri@gmail.com] 
Sent: Friday, August 03, 2007 8:22 AM
To: dev@openjpa.apache.org
Subject: Equivalent class in OpenJPA.


Hi All,

We are porting our application from Hibernate to OpenJPA in the Database
tier. We faced performance problems while processing the JPQL queries.

here are the sample code snippets:

Hibernate:

//do something

Criteria criteria = session.createCriteria(GeneralConfigDTO.class);
criteria.add(Expression.eq("name", configName)); GeneralConfigDTO
configDTO = (GeneralConfigDTO)criteria.uniqueResult();

//do something

OpenJPA:
//do something

Query query = session.createQuery("select model from GeneralConfigDTO
model where model.name = '"+configName+"'"); try{
  GeneralConfigDTO configDTO =
(GeneralConfigDTO)query.getSingleResult();
}catch(NoResultException nre){
  configDTO = null;
}catch(NonUniqueResultException ure){
  configDTO = null;
}

//do something

We have around 21 tuples in the relation "GeneralConfigDTO".

The Hibernate code snippet is getting executed in around 20msecs,
whereas, OpenJPA code snippet is taking around 400msecs, which is
accounting for overall performance of the Application.

The reason why we went for JPQL is because, we didn't find an equivalent
Hibernate's "Criteria" class in OpenJPA. 

Is there any configurations that we have to do to optimize JPQL queries.

Is there any equivalent class for "Criteria" in OpenJPA.

Any help would be highly appreciated.

Thanks in advance.

Sreedhar Sirigiri.



--
View this message in context:
http://www.nabble.com/Equivalent-class-in-OpenJPA.-tf4212515.html#a11983
221
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.