0

I created one application using Spring on Tomcat, and the second app using Java EE (EJB + JSF) on JBoss AS 7. As ORM I choose Hibernate, or I think so.

Suppose, I have a page with trip offers. I can click on a link to load trip descriptions using AJAX.

With the Spring version, after choosing a description link, only one query is sent to the database. This is good.

But with the Java EE version, in the same case, seven queries are sent! Seven queries for each trip offer displayed on the current site. So, if I can see 4 trip offers, there are 4*7 SQL queries! That is why the performance is low.

The service layer, so SQL queries, are the same in both versions. In the Spring version, the request is sent (by post) using jQuery. In Java EE, I use JSF AJAX support.

What is the cause of this behaviour? I am not sure, maybe Hibernate is not really used in the Java EE version? In persistance.xml I have the following: <provider>org.hibernate.ejb.HibernatePersistence</provider>.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
LancerX
  • 1,211
  • 7
  • 23
  • 40

1 Answers1

0

First you have to determine whether the multiple SQL queries are induced by the client or whether there's something on the backend that's different.

Try opening up Firebug or similar tool and check to see whether your browser is sending a bunch of separate HTTP requests.

  • Queries are induced by the client application. I tried to find something in Firebug. In Spring, the browser send one post with parameter tourId. In JSF post looks:j_idt30 j_idt30 javax.faces.ViewState 1890404398957610430:5258909192808903679 javax.faces.behavior.even... action javax.faces.partial.ajax true javax.faces.partial.event click javax.faces.partial.execu... j_idt30:j_idt31:0:j_idt35 j_idt30:j_idt31:0:j_idt35 javax.faces.partial.rende... j_idt30:j_idt31:0:details javax.faces.source j_idt30:j_idt31:0:j_idt35 – LancerX Aug 17 '12 at 20:16
  • Problem solved after reading this topic http://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times No DB logic in getters, solved the problem. – LancerX Aug 18 '12 at 12:26