-->
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: Query with 'LIKE' takes long to return the result -
PostPosted: Thu Nov 22, 2007 11:40 pm 
Newbie

Joined: Thu Nov 22, 2007 11:24 pm
Posts: 2
Location: Melbourne, Australia
Database - Informix
ORM done to be compatible to JPA using Hibernate3(hibernate core + hibernate annotations + hibernate entitymanager)

Issue: When I use LIKE keyword in the query , it takes three times more time comparing to exsisting in-house ORM solution to return the result.

Example:
List<PersonStudent> lis = em5.createQuery("select p from PersonStudent p " + "where p.familyNameUpper like :sn").setParameter("sn", "%NOYE%").getResultList();

This query returns 20 rows.

How the response time can be improved?


Entity class:

package example;

import java.io.Serializable;
import javax.persistence.*;
import java.sql.Date;
import java.util.*;

@Entity
@NamedQueries({
@NamedQuery(
name = "findPersonStudentByFamilyName",
query = "SELECT p FROM PersonStudent p WHERE p.familyNameUpper LIKE :familyName
"
),
@NamedQuery(
name = "findPersonStudentEnrolledInACourseInAYear",
query = "SELECT p FROM PersonStudent p JOIN p.studCseYrPer s" +
" WHERE s.studCseYrPerId.studyYear = :studyYear" +
" AND s.studCseYrPerId.cseId = :courseId")
})
@Table(name="VUSISv3:PersonStudent")
public class PersonStudent implements Serializable{
private String vuId;
private String title;
private String familyName;
private String familyNameUpper;
private String firstName;
private String secondName;
.................................................

private Set<PersonStudentAddress> psAddresses =
new HashSet<PersonStudentAddress>();
private Set<StudCseYrPer> studCseYrPer =
new HashSet<StudCseYrPer>();

@Id
@Column(name="studid")
public String getVuId() {
return vuId;
}

public void setVuId(String vuId) {
this.vuId = vuId;

}
.............................................
@OneToMany
@JoinColumn(name="studid")
public Set<PersonStudentAddress> getPsAddresses() {
return psAddresses;
}

@OneToMany
@JoinColumn(name="studid")
public Set<StudCseYrPer> getStudCseYrPer() {
return studCseYrPer;
}
.......................................
}


-------------------------------------------------------------------------------

EntityManager em5 = emf.createEntityManager();
EntityTransaction tx5 = em5.getTransaction();
List<PersonStudent> lis = em5.createQuery("select p from PersonStudent p " +
"where p.familyNameUpper like :sn").setParameter("sn", "%NOYE%").getResultList();
....................................

-Siva


Top
 Profile  
 
 Post subject: Re: Query with 'LIKE' takes long to return the result -
PostPosted: Sun Dec 09, 2007 9:22 pm 
Newbie

Joined: Thu Nov 22, 2007 11:24 pm
Posts: 2
Location: Melbourne, Australia
I am desperate to find the answer for this issue as we need that to make some critical decisions. Anyone , please provide me with some ideas.....


[quote="suthan99"]Database - Informix
ORM done to be compatible to JPA using Hibernate3(hibernate core + hibernate annotations + hibernate entitymanager)

Issue: When I use LIKE keyword in the query , it takes three times more time comparing to exsisting in-house ORM solution to return the result.

Example:
List<PersonStudent> lis = em5.createQuery("select p from PersonStudent p " + "where p.familyNameUpper like :sn").setParameter("sn", "%NOYE%").getResultList();

This query returns 20 rows.

How the response time can be improved?


Entity class:

package example;

import java.io.Serializable;
import javax.persistence.*;
import java.sql.Date;
import java.util.*;

@Entity
@NamedQueries({
@NamedQuery(
name = "findPersonStudentByFamilyName",
query = "SELECT p FROM PersonStudent p WHERE p.familyNameUpper LIKE :familyName
"
),
@NamedQuery(
name = "findPersonStudentEnrolledInACourseInAYear",
query = "SELECT p FROM PersonStudent p JOIN p.studCseYrPer s" +
" WHERE s.studCseYrPerId.studyYear = :studyYear" +
" AND s.studCseYrPerId.cseId = :courseId")
})
@Table(name="VUSISv3:PersonStudent")
public class PersonStudent implements Serializable{
private String vuId;
private String title;
private String familyName;
private String familyNameUpper;
private String firstName;
private String secondName;
.................................................

private Set<PersonStudentAddress> psAddresses =
new HashSet<PersonStudentAddress>();
private Set<StudCseYrPer> studCseYrPer =
new HashSet<StudCseYrPer>();

@Id
@Column(name="studid")
public String getVuId() {
return vuId;
}

public void setVuId(String vuId) {
this.vuId = vuId;

}
.............................................
@OneToMany
@JoinColumn(name="studid")
public Set<PersonStudentAddress> getPsAddresses() {
return psAddresses;
}

@OneToMany
@JoinColumn(name="studid")
public Set<StudCseYrPer> getStudCseYrPer() {
return studCseYrPer;
}
.......................................
}


-------------------------------------------------------------------------------

EntityManager em5 = emf.createEntityManager();
EntityTransaction tx5 = em5.getTransaction();
List<PersonStudent> lis = em5.createQuery("select p from PersonStudent p " +
"where p.familyNameUpper like :sn").setParameter("sn", "%NOYE%").getResultList();
....................................

-Siva[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 4:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Does the SQL generated query look the same?
If yes, it's probably because the Informix driver or your connection provider goes crazy on prepared statements with like: hibernate always use a porepared statement, maybe your home solution does not.

_________________
Emmanuel


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.