I've set up a Hibernate mapping (using a hbm.xml file) to a Java Bean which represents objects stored in a table in an Oracle Database. The table only has a couple of hundred rows of data. When I query it via SQL Developer it returns results immediately. But when I query it via the Hibernate mapping (ie: when I use a Java class to get a List of Beans from this table) the response is very slow - three minutes in fact. This isn't the case with other mappings I've written that map to different tables in the database. I've traced the source of the slowness to one lined of Java code
As you can see it's a basic query with no clauses and my mapping isn't doing anything complex or anything that I'm not already doing in different mappings that don't experience this issue. Does anyone know how I can delve deeper to see why this is so slow? Is this likely to be a database issue or is there something I should be doing with Hibernate to improve performance?
The class is very basic (I'm a little reluctant to post the code here as it's proprietary data for my employer). It's just a constructor with a series of getters and setters for three long variables and seven String variables. It implements the Serializable interface but that shouldn't have an impact.
I stripped all relationships out of the hbm.xml file except for the id attribute
It had no effect - the data still took over two minutes to load.
I'm timing it using debug messages. I put System.out.println(<current time>) commands after each line of the code and saw that there was a difference of two minutes before and after the line of code I highlighted in the OP (I stripped these commands out before posting the OP).
Between time checks two and three there is a gap of a couple of minutes which leads me to believe that this line is the source of the problem
posted 3 years ago
You can open Hibernate up to DEBUG or TRACE (if you need to) so you can see exactly what query is being created, but I'd be surprised if it's going to be the query for a simple entity.
But that might give you some timestamps to see where it's taking its time.
Dave Tolls wrote:You can open Hibernate up to DEBUG or TRACE (if you need to) so you can see exactly what query is being created
If you are using log4j, you can enable detailed Hibernate logging using this configuration
Simon Ritchie wrote:Between time checks two and three there is a gap of a couple of minutes which leads me to believe that this line is the source of the problem
It might be a stupid question, but how many records has this table? Because with that query it will return all records from that table. And you might be running low on memory in the end, so garbage collection could be ran several times to claim as much memory as possible (which would also slow down the execution).
 You already stated in your first post that the table only has a couple of hundred rows and that should not be any problem at all. So I would enable Hibernate logging and see which SQL statements are triggered during the execution of that statement.