Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8161027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:24:37+00:00 2026-06-06T18:24:37+00:00

i need to change my query from native-query to ( named-query or create-query )

  • 0

i need to change my query from native-query to (named-query or create-query) in jpa.

em = getEntityManager();

    String query = "SELECT kcu.table_Name FROM INFORMATION_SCHEMA.key_column_usage kcu,Information_schema.Tables kt " +
            "WHERE kcu.REFERENCED_TABLE_NAME = 'sampleTable1' " +
            "AND kcu.TABLE_SCHEMA='sampleDataBase' " +
            "AND kcu.REFERENCED_COLUMN_NAME = 'sampleRollNoId' " +
            "AND kt.table_name = kcu.table_name " +
            "AND kt.table_rows > 0 " +
            "AND kt.table_schema = kcu.table_schema";

    List tableNameList = (List) em.createNativeQuery(query).getResultList();

This query returns all tablenames (the tables names foreign key refer to this table (sampleTable1)).

I got error when i change createQuery or namedQuery.

Like

List tableNameList = (List) em.createQuery(query).getResultList();

or

List tableNameList = (List) em.createNamedQuery(query).getResultList();

How to change this query as namedQuery or createQuery. Is possible?

The following error, when i use createquery

------------- Standard Error -----------------
log4j:WARN No appenders could be found for logger 
   (org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
log4j:WARN Please initialize the log4j system properly.

Testcase: testEntryInUseNamedQuery(com.JPASampleDAOTest):        Caused an ERROR
org.hibernate.hql.ast.QuerySyntaxException: INFORMATION_SCHEMA.key_column_usage is not mapped

[SELECT kcu.table_Name FROM INFORMATION_SCHEMA.key_column_usage kcu,Information_schema.Tables kt WHERE kcu.REFERENCED_TABLE_NAME = 'sampleTable1' AND kcu.TABLE_SCHEMA='sampleDatabase' AND kcu.REFERENCED_COLUMN_NAME = 'sampleRollNoId' AND kt.table_name = kcu.table_name AND kt.table_rows > 0 AND kt.table_schema = kcu.table_schema]

java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: INFORMATION_SCHEMA.key_column_usage is not mapped [SELECT kcu.table_Name FROM INFORMATION_SCHEMA.key_column_usage kcu,Information_schema.Tables kt WHERE kcu.REFERENCED_TABLE_NAME = 'sampleTable1' AND kcu.TABLE_SCHEMA='sampleDatabase' AND kcu.REFERENCED_COLUMN_NAME = 'sampleRollNoId' AND kt.table_name = kcu.table_name AND kt.table_rows > 0 AND kt.table_schema = kcu.table_schema]
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:624)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:96)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:193)
    at $Proxy27.createQuery(Unknown Source)
 at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:198)
    at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:274)
    at org.springframework.test.context.junit4.SpringMethodRoadie$2.run(SpringMethodRoadie.java:207)
    at org.springframework.test.context.junit4.SpringMethodRoadie.runBeforesThenTestThenAfters(SpringMethodRoadie.java:254)
    at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:234)
    at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:204)
    at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:146)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:151)

Caused by: org.hibernate.hql.ast.QuerySyntaxException: INFORMATION_SCHEMA.key_column_usage is not mapped [SELECT kcu.table_Name FROM INFORMATION_SCHEMA.key_column_usage kcu,Information_schema.Tables kt WHERE kcu.REFERENCED_TABLE_NAME = 'sampleTable1' AND kcu.TABLE_SCHEMA='sampleDatabase' AND kcu.REFERENCED_COLUMN_NAME = 'sampleRollNoId' AND kt.table_name = kcu.table_name AND kt.table_rows > 0 AND kt.table_schema = kcu.table_schema]
    at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
    at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
    at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
    at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
    at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:93)

Help me,
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:24:39+00:00Added an answer on June 6, 2026 at 6:24 pm

    Use JPQL over SQL. In JPQL you refer to Entities rather than Tables and to Properties rather than Columns.

    Use em.createQuery() to execute JPQL query. em.createNamedQuery() is for different purposes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query $STH_1 = $DBH_R->query(SELECT table_name FROM information_schema.tables WHERE table_name LIKE 'v_c_ei\_9%'
I need to create native SQL query with couple of unions and subqueries. It'll
I need change background of all text that have two spaces from the start
I use Pjax with tutorial from http://railscasts.com/episodes/294-playing-with-pjax?view=comments I don't need change url and this
So I have a HQL Query like so: String query = from records where
I need to change $config['uri_protocol'] from AUTO to PATH_INFO (to allow url parameters) My
User.id type INT Avatar.foreign_key type VARCHAR When I use this query: SELECT * FROM
Debugging an app which queries SQL Server 05, can't change the query but need
i'm iterating xml node values, which i get from xpath query. And i need
I need to get the table name to query from a table. var tableName

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.