aspose file tools*
The moose likes Object Relational Mapping and the fly likes org.hibernate.exception.GenericJDBCException: could not execute query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "org.hibernate.exception.GenericJDBCException: could not execute query" Watch "org.hibernate.exception.GenericJDBCException: could not execute query" New topic
Author

org.hibernate.exception.GenericJDBCException: could not execute query

Mahender Gajapaga
Greenhorn

Joined: Aug 21, 2009
Posts: 2
Hi,

below are our environment details:

jdk1.5.0_14,
Hibernate-3.2.6,
WebLogic Server- 9.2.2.0
DB2 v9.1.6

we have an issue where we get org.hibernate.exception.GenericJDBCException: could not execute query
when we try to execute query using either org.hibernate.Criteria.list() or org.hibernate.Query.list()
its weird that this doesn't happen always,

any suggestion would be appreciated.

stack trace

FATAL - caught HibernateException during user search [org.hibernate.exception.GenericJDBCException: could not execute query]
FATAL - org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
org.hibernate.loader.Loader.doList(Loader.java:2231)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
org.hibernate.loader.Loader.list(Loader.java:2120)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
1. Show your code.
2. Do you have the proper table in database?
3. What database do you use?
4. Show your data source. Do your use has proper rights?
Mahender Gajapaga
Greenhorn

Joined: Aug 21, 2009
Posts: 2
Hi Stanislav,

we are using DB2 v9.1.6, tables/permission are properly setup cause the same code works fine most of the time.

below is the sample code

public List getxxData(input parms) {
try {

/*-------------------------------------------------------------+
| Save off the current isolation level |
+-------------------------------------------------------------*/
HibernateUtil.setIsolationLevel(Tsession,
Connection.TRANSACTION_READ_UNCOMMITTED);

/*-------------------------------------------------------------+
| Ok now setup our criteria for the search |
+-------------------------------------------------------------*/
Criteria Tcrit=Tsession.createCriteria(Student.class);

if (Pstdate != null) {
Tcrit.add(Restrictions.eq("startDate", Pstdate));
} /*endif*/

if (PendDate != null) {
Tcrit.add(Restrictions.eq("endDate", PendDate));
} /*endif*/

Tcrit.addOrder(Order.asc("userName"));

/*-------------------------------------------------------------+
| Set it up to and all the expressions |
+-------------------------------------------------------------*/
Tcrit.add(Restrictions.conjunction());

/*-------------------------------------------------------------+
| Now execute the query and we should be good |
+-------------------------------------------------------------*/
List Trlist = Tcrit.list();
} catch () {
} finally {
} //end try
}// end method

hibernate config

<hibernate-configuration>
<session-factory>
<!-- Connector definitions -->
<!-- property: hibernate.connection.driver_class com.mysql.jdbc.Driver -->
<!-- property: hibernate.connection.url jdbc:mysql://localhost:3306/test -->
<!-- property: hibernate.connection.username xxx -->
<!-- property: hibernate.connection.password xxxx -->
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.connection.datasource">xyzDatasource</property>
<property name="hibernate.max_fetch_depth">0</property>
<!-- property: hibernate.hbm2ddl.auto create-drop -->
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<!-- property: hibernate.transaction.factory_class org.hibernate.transaction.JDBCTransactionFactory -->
<property name="hibernate.current_session_context_class">thread</property>
<property name="default_schema">test</property>

<!-- Use the C3P0 connection pool provider -->
<!-- property: hibernate.c3p0.min_size 5 -->
<!-- property: hibernate.c3p0.max_size 20 -->
<!-- property: hibernate.c3p0.timeout 300 -->
<!-- property: hibernate.c3p0.max_statements 50 -->
<!-- property: hibernate.c3p0.idle_test_period 3000 -->

<!-- Show and print nice SQL on stdout -->
<property name="show_sql">false</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>

<!-- List of XML mapping files -->
<mapping class="com.test.tst.hb.Student"/>
</session-factory>
</hibernate-configuration>
stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
Hibernate has several types of exception:
JDBCConnectionException - indication an error with the underlying JDBC communication.
SQLGrammarException - indicates grammar or syntax problem with the issued SQL.
ConstraintViolationException - indicates some form of integrity constraint violation.
LockAcquisitionException - indication an error acquiring a lock level necessary to perform the requested operation.
and the last one:
GenericJDBCException - a generic exception which did not fail into any of the other categories.

So it maybe any of problem except the specified. Try to change any conditions: criteria, level of transaction isolation, everything that may create this problem. Sorry, but I cannot help you( maybe someone else can..
Rahul Babbar
Ranch Hand

Joined: Jun 28, 2008
Posts: 210
why don't you just set the "show_sql" to true, see what Sql is getting executed....and proceed further..


Rahul Babbar
Shailesh Karwa
Greenhorn

Joined: Mar 29, 2012
Posts: 1
I also got the same org.hibernate.exception.GenericJDBCException and found that it came when my SQL query contains join syntax (INNER JOIN) and also other type of join syntax : - (+) so the thing is i have to use only one type of syntax for joining tables i.e. either (+) or (JOIN keyword)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.hibernate.exception.GenericJDBCException: could not execute query