Thursday, August 27, 2009

Java - Hibernate - MYSQL

Hi,
In this blog, I want to share my experience when I am using hibernate
Hibernate is very good framework which makes developer work very easy, but when we are doing some stuff like calling some stored procedures etc, we will face some issues
I have listed out some issues which I faced.
This we can do in two ways
1) Normal JDBC call.
Code:
Connection con = getSession().connection();
String CompIDList = compList.toString();
java.sql.CallableStatement st = con.prepareCall(" { CALL Test (?, ?) } ");
st.setString("tagName", tag.getName());
st.setString("comList",compList);
st.execute();

The issuses when we are using the above method.
When we don't have proper premission on the server. we will face the following issuses
Error :
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectQuotes(StringUtils.java:948)
at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1255)
at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3640)
at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:506)
at com.mysql.jdbc.CallableStatement.(CallableStatement.java:401)
at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4072)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4146)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

Sloution :
Just the premissions of the user to admin.
or
provide the username & password with admin premissions.


2) Using the hibernate
code :
Query query = getSession().getNamedQuery("createTagging");
query.setParameter(0, tag.getName() );
query.setParameter(1, compList );
System.out.println("TagDAO.createTag() .... "+query);
query.executeUpdate();

Error :
4:54:01,978 ERROR hibernate.TagDAO:182 - save failed
java.lang.IllegalArgumentException: callable not yet supported for native queries
at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:147)
at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1163)
at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:334)

Solution:
Update the hibernate jars with latest version.

No comments: