aspose file tools*
The moose likes Object Relational Mapping and the fly likes JPA native query problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA native query problem" Watch "JPA native query problem" New topic
Author

JPA native query problem

Shridhar Raghavan
Ranch Hand

Joined: May 27, 2010
Posts: 71
Hi,

I am executing a native SQL query in JPA. No entities involved



The problem i am facing is when the query string is projecting a column of type TEXT in db, the code throws an exception

javax.persistence.PersistenceException: org.hibernate.MappingException: No Dialect mapping for JDBC type: -1
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:74)

The same query works if i change the datatype of the column to VARCHAR. Is there a limitation of JPA with TEXT or is the problem altogether different.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

-1 is the value of Types.LONGVARCHAR. Now I don't know JPA or Hibernate that well so I don't know its default mappings. I'll move this thread to our ORM forum where people probably do know.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tanya Ruttenberg
Ranch Hand

Joined: Jun 22, 2009
Posts: 40
I am having exactly the same problem. I am using org.hibernate.dialect.MySQL5InnoDBDialect.
The "config" column type MEDIUMTEXT. As you can see I'm trying to cast the result simply as a String.



Any idea on how to work around the problem?
Shridhar Raghavan
Ranch Hand

Joined: May 27, 2010
Posts: 71
I spent a couple of hours on this and moved on. Here's a few alternatives. Try using hibernate's implementation of the API. Or else use simple jdbc metadata. Both will mean a significant change in code. The simplest solution is change the column type in the database. Unfortunately, I had to write jdbc code as I didnt receive approval for schema modification. Hope someone sorts this out.
Shridhar Raghavan
Ranch Hand

Joined: May 27, 2010
Posts: 71
Here's a few things I checked out.

http://stackoverflow.com/questions/986094/jpa-native-query-for-longtext-field-in-a-mysql-view-results-in-error

https://hibernate.onjira.com/browse/HHH-3892

https://hibernate.onjira.com/browse/HHH-1483








Tanya Ruttenberg
Ranch Hand

Joined: Jun 22, 2009
Posts: 40
Thanks! Of course I scoured the web and didn't find the posting that would help me.

I followed the instructions in the stackoverflow posting exactly and it worked great. I've never extended a dialect before!

patting myself on the back....
TDR
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JPA native query problem