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 6964681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:57:19+00:00 2026-05-27T15:57:19+00:00

I have an application which uses Spring and Hibernate. In my database there are

  • 0

I have an application which uses Spring and Hibernate. In my database there are some views that I need to load in some entities. So I’m trying to execute a native query and load the class withthe data retrieved from the view:

//In my DAO class (@Repository) 
public List<MyClass> findMyEntities(){
    Query query = em.createNativeQuery("SELECT * FROM V_myView", MyClass.class);
    return query.getResultList();
}

and MyClass has the same fields as the column names of the view.

The problem is that Hibernate can’t recognize MyClass because it’s not an entity (it’s not annotated with @Entity)

org.hibernate.MappingException: Unknown entity

If I put MyClass as an entity the system will put try to create/update a table for that entity, because I have configured it :

<property name="hibernate.hbm2ddl.auto" value="update"/>

So I come into these questions:

  1. Can I disable “hibernate.hbm2ddl.auto” just for a single entity?
  2. Is there any way to load the data from a view into a non-entity class?
  3. If not, what would be the best way in my case for loading the data from a view into a class in hibernate?

Thanks

  • 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-05-27T15:57:20+00:00Added an answer on May 27, 2026 at 3:57 pm

    You may use axtavt solution. You may also just execute your query, and transform the List<Object[]> it will return into a List<MyClass> explicitely. Or you may map your view as a read-only entity, which is probably the best solution, because it would allow for associations with other tables, querying through JPQL, Criteria, etc.

    In my opinion, hibernate.hbm2ddl.auto should only be used for quick n’ dirty prototypes. Use the hibernate tools to generate the SQL file allowing to create the schema, and modify it to remove the creation of the view. Anyway, if it’s set to update, shouldn’t it skip the table creation since it already exists (as a view)?

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

Sidebar

Related Questions

I have a Spring application which uses Hibernate on a PostgreSQL database. I'm trying
I have an application which uses Spring 2.5 and Hibernate 3. There's a web
I have a JPA/Spring application that uses Hibernate as the JPA provider. In one
We have a web application which uses Struts 2, Spring and Hibernate. Currently a
I have application, which uses Spring, Hibernate and Spring Security. My goal is to
I have a PHP web application which uses a MySQL database for object tagging,
I have a client application that connects to a server. The server uses hibernate
I have a java web application which uses spring webflow as framework. I have
I currently have an application which uses EF database first which was built against
I have an asp.net mvc application, which uses the default user database. It all

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.