File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
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

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

Mahender Gajapaga

Joined: Aug 21, 2009
Posts: 2

below are our environment details:

WebLogic Server-
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(
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

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 |

| 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*/


| Set it up to and all the expressions |

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

hibernate config

<!-- 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: 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"/>
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

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:
subject: org.hibernate.exception.GenericJDBCException: could not execute query
It's not a secret anymore!