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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:56:58+00:00 2026-06-17T12:56:58+00:00

I’m new to Hibernate, I downloaded a sample Java app and modified it to

  • 0

I’m new to Hibernate, I downloaded a sample Java app and modified it to be more useful, so far in my app I have two db classes that are defined in my Java app : Actor.java and City.java
Each of them has a .hbm.xml file look like the following :

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 17, 2009 11:42:48 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="sakila.entity.Actor" table="actor" catalog="sakila">
        <id name="actorId" type="java.lang.Short">
            <column name="actor_id" />
            <generator class="identity" />
        </id>
        <property name="firstName" type="string">
            <column name="first_name" length="45" not-null="true" />
        </property>
        <property name="lastName" type="string">
            <column name="last_name" length="45" not-null="true" />
        </property>
        <property name="lastUpdate" type="timestamp">
            <column name="last_update" length="19" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="sakila.entity.City" table="city" catalog="sakila">
        <id name="cityId" type="java.lang.Short">
            <column name="city_id" />
            <generator class="identity" />
        </id>
        <property name="city" type="string">
            <column name="city" length="45" not-null="true" />
        </property>
        <property name="countryId" type="string">
            <column name="country_Id" length="45" not-null="true" />
        </property>
        <property name="lastUpdate" type="timestamp">
            <column name="last_update" length="19" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

The app works great so far. But my question is, what if I need to change my app so that it can handle hundreds of objects like Actor and City in the db, do I need to define all the mapping files ? What if I don’t know at the time of programming what db objects user might query, do I need to define all of them, that seems impossible, so my question is : is the *.hbm.xml files necessary ? In the case I need to write an app that lets user query whatever objects he needs, and I may not even know what’s in the db, how to write such an app ? Doable with Hibernate ?

  • 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-17T12:57:00+00:00Added an answer on June 17, 2026 at 12:57 pm

    If your system is so dynamic that you don’t know the tables that a user will be querying then I cannot see how you would be mapping these tables to corresponding POJOs. The primary emphasis of Hibernate is mapping tables in your schema to objects in your Java application, primarily through the Hibernate Query Language (HQL) or one of the programatic APIs that are available.

    However, it is possible to use straight SQL in hibernate and return non-managed objects, although this is far more limited in capability than using HQL or the query APIs. To do this you would use code similar to the following:

    createSQLQuery( "SELECT * FROM someTable" ).addTransformer(Transformers.aliasToBean(MyJavaClass.class));
    

    This transformer maps columns in your SQL query, by name, to properties of the specified POJO. In practice, type conversions are challenging and .setScalar is required in many cases. You can also use Transformers.aliasToEntityMap which returns a list of maps, where each map is a mapping of column name to value.

    This is covered, briefly, in section 18.1.5 of the current Hibernate Core documentation.

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

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have been unable to fix a problem with Java Unicode and encoding. The
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.