Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JPA native query problem

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 22461
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-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.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 71
 
Tanya Ruttenberg
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic