Hibernate Issuing too many queries in MySQL

I am using hibernate 3.0 in spring with Mysql 5. I configured the JNDI data source in JBOSS and used it in the application context.

My problem is that Hibernate issues an average of 466.4 queries per second to the database, almost without loading the website.

Fragment ApplicationContext.xml -

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" scope="singleton"> <property name="jndiName" value="java:MyCustomDSName" /> <property name="resourceRef" value="true" /> </bean> 

I am using a Java level JTA transaction. Any help is appreciated.

+4
source share
3 answers

One of them should be in this case

  • You receive / process too many requests - unlikely in dev.
  • You use the selection condition N + 1 - very often.

Submit your domain model and running requests.

+1
source

How do you use JTA transactions? If a new transaction is required for each Java method, this may explain part of your problem. In addition, you must reconsider the relationship of the Hibernate object. If you have complex relationships, a lot of loaded objects, defined in your model relationships or circular relationships, you can solve more complex problems.

0
source

You can solve problems with N + 1 query directly from unit tests . Also, switch all EAGER associations to LAZY and initialize the ones you need at the time of the request with JOIN FETCH .

0
source

Source: https://habr.com/ru/post/1345332/


All Articles