Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Performance issues @ManyToOne @OneToMany
PostPosted: Fri Mar 08, 2013 12:30 pm 
Newbie

Joined: Fri Mar 08, 2013 11:55 am
Posts: 1
Hi, I anyone could assist me I would appreciate it.

I am having perfomace issues running a simple query in hibernate. On my localhost it takes about 9 seconds to return about 7000 rows. On a remote server it takes about 3 seconds to return the 7000 rows. When I run the SQL natively through a database client (Toad) it takes about 300ms. This suggests that the time is being spent in the marshalling of the of the result set into java objects.

I have 3 tables:
workitemhistory - n:1 - workitem - n:1 - initiative

The sql I run is:
Code:
         String sql = "SELECT h FROM WorkItemHistory h "+
               "WHERE h.workItem.initiative.prn IN :prns "+
               "ORDER BY h.dayModified";//, h.workItem.state.group";
         Query query = em.createQuery(sql);
         query.setParameter("prns", prns);
         final List<WorkItemHistory> results = query.getResultList();
         return results;

I have also tried the following with the same result:
Code:
         String sql = "SELECT h.* FROM workitemhistory h "+
            "INNER JOIN workitem w ON w.id = h.workitem_id "+
            "INNER JOIN initiative i ON i.id = w.initiative_id AND i.prn IN :prns "+
            "ORDER BY h.daymodified, h.stategroup";
         Query query = em.createNativeQuery(sql, WorkItemHistory.class);
         query.setParameter("prns", prns);
         final List<WorkItemHistory> results = query.getResultList();
         return results;


My beans are mapped as follows:
WorkItemHistory
Code:
   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "workitem_id")
   public WorkItem getWorkItem() {
      return workItem;
   }

WorkItem
Code:
   @OneToMany(mappedBy = "workItem", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
   public List<WorkItemHistory> getWorkItemHistory() {
      return workItemHistory;
   }


   @ManyToOne (fetch = FetchType.EAGER)
   @JoinColumn(name = "initiative_id")
   public Initiative getInitiative() {
      return initiative;
   }

Initiative
Code:
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Column(name = "id")
   public Integer getId() {
      return id;
   }


I have tried Lazy loading of the WorkItemHistory, but need the WorkItems and get a org.hibernate.LazyInitializationException.

Please can anyone advise on how to make this faster? Surely hibernate should not take so long to Marshall serveral thousand rows? If I were to use jdbc and put these in a java object, it would be a lot faster.

Thanks in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

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.