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.  [ 3 posts ] 
Author Message
 Post subject: EJB3 MySQL Stored Procedure Column Not Found
PostPosted: Sun Jul 06, 2008 1:51 am 
Newbie

Joined: Mon Jul 03, 2006 4:28 pm
Posts: 15
Hibernate Core - 3.2
Annotations - 3.3.1.GA
Entity Manager - 3.3.2.GA
Database - MySQL 5.0

I'm trying to map a call to a MySQL Stored procedure back to an entity in ejb 3 and am getting a really odd error. Can anyone shed some light?

The stored procedure signature is:

Code:
CREATE PROCEDURE `sp_createIndustrySnapshot`
  (IN country VARCHAR(15), IN state VARCHAR(15), IN industry VARCHAR(10))


I've tested it in MySQL query browser and it works fine. I'm trying to use the following EJB 3 mapping to execute it:

Code:
@NamedNativeQueries({
    @NamedNativeQuery(
        name="createIndustrySnapshot",
        resultSetMapping="createIndustrySnapshotMapping",       
        query="{call sp_createIndustrySnapshot(?, ?, ?)}",
        hints={
            @QueryHint(name="org.hibernate.callable", value="true")
        }
    )
})
@SqlResultSetMappings({
    @SqlResultSetMapping(
        name="createIndustrySnapshotMapping",
        entities={
            @EntityResult(entityClass=com.myapp.IndustryStatistic.class,
                fields={
                    @FieldResult(name="oneMonthGrowthRate", column="ONE_MONTH_GROWTH"),
                    @FieldResult(name="threeMonthGrowthRate", column="THREE_MONTH_GROWTH"),
                    @FieldResult(name="sixMonthGrowthRate", column="SIX_MONTH_GROWTH"),
                    @FieldResult(name="oneYearGrowthRate", column="TWELVE_MONTH_GROWTH"),
                    @FieldResult(name="avgDaysOpen", column="AVG_DAYS_OPEN")
                }           
            )
        }
    )
})



I'm calling this using the following code:

Code:
            Query q = em.createNamedQuery("createIndustrySnapshot");
            q.setParameter(1, countryCode);
            q.setParameter(2, stateCode);
            q.setParameter(3, industry.getCode());
            stats.add((IndustryStatistic)q.getSingleResult());


I've tested the call using good old fashioned jdbc con.prepareCall and it works fine. I've given the user select access to mysql.proc so there should be no problem there.

I get the following error, anyone have any ideas?

Code:
2008-07-06 15:25:09,312 [httpSSLWorkerThread-8080-1] DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2008-07-06 15:25:09,312 [httpSSLWorkerThread-8080-1] DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2008-07-06 15:25:09,312 [httpSSLWorkerThread-8080-1] DEBUG org.hibernate.util.JDBCExceptionReporter - could not execute query [{call sp_createIndustrySnapshot(?, ?, ?)}]
java.sql.SQLException: Column 'industry1_227_0_' not found.
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
   at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:955)
   at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5436)
   at org.hibernate.type.StringType.get(StringType.java:18)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
   at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1097)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:565)
   at org.hibernate.loader.Loader.doQuery(Loader.java:701)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
   at org.hibernate.loader.Loader.doList(Loader.java:2220)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
   at org.hibernate.loader.Loader.list(Loader.java:2099)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
   at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:82)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 3:13 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
see my response on http://forum.hibernate.org/viewtopic.php?t=988406

_________________
Carlo
-----------------------------------------------------------
please don't forget to rate if this post helped you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 9:27 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
When you see these java.sql.SQLException objects, it typically has to do with a mapping somewhere. Hibernate has done what you've asked it to do, but at a low level, the table or column it is looking for doesn't exist.

Check your mappings!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.