I am using Hibernate 4.2, JPA 2.0 & Postgres 9.2
The code gets stuck at Persistence.createEntityManagerFactory("peristence_unit_name");
On further investigation I found that Hibernate makes a call to getTypeInfo()
method of java.sql.DatabaseMetaData
class. This method tries to load metadata about every database object
/**
* Perform the extraction
*
* @param metaData The JDBC metadata
*
* @return The extracted metadata
*/
public static LinkedHashSet<TypeInfo> extractTypeInfo(DatabaseMetaData metaData) {
LinkedHashSet<TypeInfo> typeInfoSet = new LinkedHashSet<TypeInfo>();
try {
ResultSet resultSet = metaData.getTypeInfo(); // << Gets stuck here.
try {
......
The code for getTypeInfo()
is part of Postgers' JDBC drivers and it is indeed the driver thats taking time to execute the method (I loaded the driver source and tried following the trail). But since this problem did not occur in Hibernate 3.3 (which I was using earlier), I think, Hibernate 3.3 was not calling this method, but Hibernate 4.2 is.
Is there a way to solve this problem? Note that the same setup with Hibernate 3.3 was working fine.
Extra Info : What the driver is doing all this time:
It first gets the list of database objects and then loops through the resultset to get metadata of each object.
There are around 3000 objects in the DB (I have a very large data-set requiring many partition tables. Plus PostGIS has many objects of its own)
It takes about 1 second per object lookup, so it takes about 3000 seconds to finish the call.