-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: "could not load an entity" Hibernate Exception
PostPosted: Thu May 07, 2009 9:14 am 
Newbie

Joined: Thu May 07, 2009 8:51 am
Posts: 2
Hi,

I am beginner in Hibernate. I am working on a project where a data load program updates the db2 tables with data from a web service every day. The same code works perfectly fine on DEV environment but doesn't work on PROD environment. The DB2 version and the OS versions are same in both the environments.

DB2/6000 8.2.9

I am using the c3p0-0.8.5.2.jar and hibernate3.jar

The PROD environment was created using db2look utility to generate the ddls in DEV environment and those ddls were executed in the PROD environment to create the tables. Later the data was imported into the PROD environment from DEV environment.

When the same set of java code is executed in PROD environment I get the following exception:


org.hibernate.exception.GenericJDBCException: could not load an entity: [com.ibm.iiw.webservices.dbo.DeliverableDependency#2056JCA]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1285)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:141)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:126)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2496)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:249)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
at com.ibm.iiw.webservices.dao.DeliverableDependencyBean.findDeliverableDependency(DeliverableDependencyBean.java:67)
at com.ibm.iiw.webservices.retrieval.StarterClassDeliverable.process(StarterClassDeliverable.java:1865)
at com.ibm.iiw.webservices.retrieval.StarterClassDeliverable.main(StarterClassDeliverable.java:129)
Caused by: java.sql.SQLException: You can't operate on a closed connection!!!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:68)
at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareStatement(NewProxyConnection.java:198)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:379)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:320)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:86)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1089)
at org.hibernate.loader.Loader.doQuery(Loader.java:365)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1271)



Which later causes the below mentioned exception

org.hibernate.exception.GenericJDBCException: could not insert: [com.ibm.iiw.webservices.dbo.DeliverableDependency]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1882)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2214)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:675)
at com.ibm.iiw.webservices.dao.BaseBean.insert(BaseBean.java:92)
at com.ibm.iiw.webservices.dao.DeliverableDependencyBean.insert(DeliverableDependencyBean.java:91)
at com.ibm.iiw.webservices.retrieval.StarterClassDeliverable.process(StarterClassDeliverable.java:1873)
at com.ibm.iiw.webservices.retrieval.StarterClassDeliverable.main(StarterClassDeliverable.java:129)
Caused by: java.sql.SQLException: You can't operate on a closed connection!!!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:68)
at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareStatement(NewProxyConnection.java:198)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:379)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:74)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:67)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:148)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1852)
... 12 more
Caused by: java.lang.NullPointerException
at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareStatement(NewProxyConnection.java:173)



Any help or pointers will be greatly helpfull. Thanks in advance!

Sudi


Top
 Profile  
 
 Post subject: Re: "could not load an entity" Hibernate Exception
PostPosted: Fri May 08, 2009 9:26 am 
Beginner
Beginner

Joined: Tue Mar 10, 2009 11:50 pm
Posts: 23
How are you providing the hibernate mappings for the entity you are trying to load?

I guess you have not configured the entities in the hibernate.cfg.xml (if using annotations for mapping) or hbm.xml

_________________
Cheers,

Vinod
We act as though comfort and luxury were the chief requirements of life, when all that we need to make us happy is something to be enthusiastic about


Top
 Profile  
 
 Post subject: Re: "could not load an entity" Hibernate Exception
PostPosted: Fri May 08, 2009 2:12 pm 
Senior
Senior

Joined: Thu Jan 08, 2009 3:48 pm
Posts: 168
Quote:
Caused by: java.sql.SQLException: You can't operate on a closed connection!!!


I would suggest you start searching there...

Rating is welcome

Patrik


Top
 Profile  
 
 Post subject: Re: "could not load an entity" Hibernate Exception
PostPosted: Thu May 14, 2009 10:38 am 
Newbie

Joined: Thu May 07, 2009 8:51 am
Posts: 2
Hi,

My java program is a data load program which daily runs and inserts/updates data in DB2 tables using hibernate.

Now while data load , we expect there might be ConstraintViolationException, So I am pasting the code which I am using to insert below.

public boolean insert() {
logger.debug("Attempting to INSERT the session: " + getDObject());
try {
Session hibSession = HibernateUtil.currentSession();
Transaction tx = hibSession.beginTransaction();
logger.debug("successfully began the transaction ");
hibSession.save(getDObject());
hibSession.flush();
logger.debug("successfully flushed the session" );
hibSession.clear();
tx.commit();
} catch(ConstraintViolationException e){
logger.error("ConstraintViolation Exception encountered while inserting database object.", e);
return false;

}
catch (JDBCException e) {
logger.error("JDBC Exception encountered while inserting database object.", e);
HibernateUtil.jdbcExceptionHandler(e);
return false;
} catch (HibernateException e) {
logger.error("Problem inserting object " + dObject, e);
e.printStackTrace();
return false;
}
logger.debug("INSERT successful for the session: " + getDObject());

return true;
}

HibernateUtil Methods

public static Session currentSession() throws HibernateException {
Session s = (Session) threadLocal.get();
logger.debug("The session value is " + s);
// System.err.println("Getting session for "+s+" thread = "+Thread.currentThread());
try {
// Check if the connection is closed
if(s!=null)
{
logger.debug(" The connection is Closed " + s.connection().isClosed());
}

// Open a new Session, if this Thread has none yet
if (s == null) {
logger.debug("The session value is null so opening a new session");
s = sessionFactory.openSession();
logger.debug("successfully opened the session");
threadLocal.set(s);
logger.debug("successfully set the value in localthread");
}
} catch (JDBCException e) {
System.err.println("Am unable to create a session due to JDBC Exception");
jdbcExceptionHandler(e);
}
logger.debug(" Final returned session value is " + s);
return s;
}

public static void jdbcExceptionHandler(JDBCException e) {
logger.error("Problem with JDBC Connection. SQL error code=" + e.getErrorCode(), e);

try {
HibernateUtil.closeSession();
} catch (HibernateException he) {
logger.error("Problem trying to close session", he);
}
// -803 indicates that the entry already exists. No point exiting over existing entry
if (e.getErrorCode() != -803) {

// logger.error("SQL error code=" + e.getErrorCode() + " fatal error has occured ");
// Commented these lines to test the daily load in Production
logger.error("SQL error code=" + e.getErrorCode() + " exiting");
systemExit(2);
}
}
static public synchronized void systemExit(int code) {
logger.fatal("Runtime.getRuntime().halt(2)...");
Runtime.getRuntime().halt(2);
}





So the main program loops over a arrayList and calls this insert one by one, when we encounter ConstraintViolationException we just catch it and return false. so it proceeds to insert the next object in the loop. But this code works fine in UAT environment but in Production as soon as the first constraintViolation occurs the next time the connection is closed.

I even tried closing the connection in the catch(ConstraintViolationException e) block. In such case I get the following exception.

[IBM][CLI Driver] SQL1040N The maximum number of applications is already connected to the database. SQLSTATE=57030

at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2Connection.connect(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2Connection.<init>(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2Driver.connect(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:68)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:87)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1.acquireResource(C3P0PooledConnectionPool.java:83)
at com.mchange.v2.resourcepool.BasicResourcePool.assimilateResource(BasicResourcePool.java:884)
at com.mchange.v2.resourcepool.BasicResourcePool.acquireUntil(BasicResourcePool.java:601)
at com.mchange.v2.resourcepool.BasicResourcePool.access$400(BasicResourcePool.java:31)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1079)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:354)
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver] SQL1040N The maximum number of applications is already connected to the database. SQLSTATE=57030



My Hibernate config file entries are as follows :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- properties -->
<!-- Connection driver depending on which database java driver you are using -->
<property name="connection.driver_class">COM.ibm.db2.jdbc.app.DB2Driver</property>
<!-- Hibernate dialect class. This differs depending on the type of database being used -->
<property name="dialect">org.hibernate.dialect.DB2Dialect</property>
<!-- If true, displays all generated SQL to System.out -->
<property name="show_sql">true</property>
<property name="cglib.use_reflection_optimizer">false</property>
<!-- All c3po properties required to optimize connection pooling -->
<property name="c3p0.minPoolSize">5</property>
<property name="c3p0.maxPoolSize">40</property>
<property name="c3p0.timeout">30</property>
<property name="c3p0.idle_test_period">3000</property>
<property name="c3p0.maxIdleTime">5000</property>
<property name="c3p0.maxPoolSize">40</property>
<property name="c3p0.maxStatements">27</property>
<property name="c3p0.forceIgnoreUnresolvedTransactions">true</property>
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">1000</property> <!-- seconds -->
<property name="c3p0.max_size">100</property>
<property name="c3p0.max_statements">20</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">100</property> <!-- seconds -->

<!-- my local test DB -->

<property name="connection.url">jdbc:db2:sample</property>
<property name="connection.connect2">DB2ADMIN</property>
<property name="connection.connectDetails2">db2admin</property>


<!-- The database jdbc url so hibernate knows where to persist -->
<!-- Encoded user_name -->
<!-- Encoded authentication pass_word -->
<!-- starting of code added by jihe -->
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<!-- stopping of code added by jihe -->

<!-- The names of all the mapping files used to map java classes to tables and establish their relationships -->
<mapping resource="iiw.hbm.xml"/>

</session-factory>
</hibernate-configuration>


It is a very urgent issue. Any Help will be greatly appreciated.

Thanks in advance!
Sudipto


Top
 Profile  
 
 Post subject: Re: "could not load an entity" Hibernate Exception
PostPosted: Wed Jul 21, 2010 4:57 am 
Beginner
Beginner

Joined: Mon Aug 22, 2005 9:57 pm
Posts: 27
Hey Did you solve your problem? i have same problem as you, although in each call i closed jdbc connection via session.close
but i still get ERROR JDBCExceptionReporter:78 - [IBM][CLI Driver] SQL1040N The maximum number of applications is already connected to the database. SQLSTATE=57030


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

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.