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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:29:48+00:00 2026-06-15T19:29:48+00:00

Is it possible to use the entity-name attribute in class to set an entity

  • 0

Is it possible to use the entity-name attribute in class to set an entity and to reference it? I want to do this because I want to map to multiple tables with the same entity class.

Table 1 and adble 2 have the same schema

@Entity
public class POJO{
    @Id
    @Column(name="column1")
    private String column1;

    @Column(name="column2")
   private String column2;

   //getters and setters

}



<hibernate mapping>
    <class name="package.POJO" entiy-name="EntityTable1" table="table1">
        <id>.....</id>
            <property>....</property>
            <property>....</property>
     </class>

     <class name="package.POJO" entiy-name="EntityTable2" table="table2">
        <id>.....</id>
            <property>....</property>
            <property>....</property>
     </class>
</hibernate mapping>


Session s = SessionFactory.openSession();
List table1List = s.createQuery("FROM EntityTable1").list();

List table1List = s.createQuery("FROM EntityTable2").list();

I read in the Hibernate Documentation that this is only in the experimental stage. Has anyone used this method and work?

  • 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-15T19:29:50+00:00Added an answer on June 15, 2026 at 7:29 pm

    Yes, you can do this via XML, I didn’t experience any problems with that. Here’s an example from this project (since it’s being a long time since I touched that project, I’m not cleaning up the code to show the minimal working example):

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
      <class name="org.jtalks.common.model.entity.Property" table="PROPERTIES">
    
        <id column="PROPERTY_ID" name="id" unsaved-value="0">
          <generator class="native" />
        </id>
    
        <property column="UUID" name="uuid" not-null="true" unique="true" />
        <property column="NAME" name="name" not-null="true" unique="false" />
        <property column="VALUE" name="value" type="text" not-null="false" unique="false" />
        <property column="VALIDATION_RULE" name="validationRule" not-null="false" unique="false" />
    
      </class>
    </hibernate-mapping>
    

    And:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
      <class name="org.jtalks.common.model.entity.Property" table="DEFAULT_PROPERTIES" entity-name="DefaultProperty">
        <id column="PROPERTY_ID" name="id" unsaved-value="0">
          <generator class="native" />
        </id>
        <property column="UUID" name="uuid" not-null="true" unique="true" />
        <property column="NAME" name="name" not-null="true" unique="false" />
        <property column="VALUE" name="value" not-null="false" unique="false" />
        <property column="VALIDATION_RULE" name="validationRule" not-null="false" unique="false" />
      </class>
    </hibernate-mapping>
    

    Here’s an example of usage #1

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
    
      <class name="org.jtalks.common.model.entity.Component" table="COMPONENTS">
        <id column="CMP_ID" name="id" unsaved-value="0">
          <generator class="native" />
        </id>
        
        <discriminator column="COMPONENT_TYPE" force="false" insert="false" />
        
        <property column="UUID" name="uuid" not-null="true" unique="true" />
        
        <property column="NAME" name="name" not-null="true" unique="true" />
        <property column="DESCRIPTION" name="description" />
        
        <bag name="properties" cascade="all-delete-orphan" inverse="false" lazy="false">
          <cache usage="nonstrict-read-write" region="org.jtalks.EHCOMMON"/>
          <key column="CMP_ID" foreign-key="FK_COMPONENT" />
          <one-to-many class="org.jtalks.common.model.entity.Property" />
        </bag>
    
        <property name="componentType" column="COMPONENT_TYPE" unique="true">
          <type name="org.hibernate.type.EnumType">
            <param name="enumClass">org.jtalks.common.model.entity.ComponentType</param>
            <!-- 12 means 'VARCHAR', see java.sql.Types.VARCHAR -->
            <param name="type">12</param>
          </type>
        </property>
    
        <!-- discriminator - ComponentType.FORUM -->
        <subclass name="org.jtalks.poulpe.model.entity.Jcommune" discriminator-value="FORUM">
          <list name="sections" cascade="all-delete-orphan" inverse="false" lazy="false">
            <cache usage="nonstrict-read-write" />
            <key column="COMPONENT_ID" foreign-key="FK_JCOMMUNE" />
            <list-index column="POSITION" />
            <one-to-many class="org.jtalks.poulpe.model.entity.PoulpeSection" />
          </list>
        </subclass>
        
        <!-- discriminator - ComponentType.ADMIN_PANEL -->
        <subclass name="org.jtalks.poulpe.model.entity.Poulpe" discriminator-value="ADMIN_PANEL" />
        
        <subclass name="org.jtalks.common.model.entity.Component" entity-name="Antarticle" discriminator-value="ARTICLE" />
      </class>
    </hibernate-mapping>
    

    And here’s #2 respectively:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
      <class name="org.jtalks.poulpe.model.entity.ComponentBase" table="BASE_COMPONENTS">
        <id column="COMPONENT_TYPE" name="componentType">
          <type name="org.hibernate.type.EnumType">
            <param name="enumClass">org.jtalks.common.model.entity.ComponentType</param>
            <!-- 12 means 'VARCHAR', see java.sql.Types.VARCHAR -->
            <param name="type">12</param>
          </type>
        </id>
        
        <set name="defaultProperties" cascade="all" inverse="false" lazy="false">
          <cache usage="read-only" />
          <key column="BASE_COMPONENT_TYPE" foreign-key="COMPONENT_TYPE" />
          <one-to-many class="org.jtalks.common.model.entity.Property" entity-name="DefaultProperty" />
        </set>
      </class>
    </hibernate-mapping>
    

    Note, that you can’t do that same with annotations, that’s where XML is more flexible.

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

Sidebar

Related Questions

I use Entity Framework 4.0. Is it possible that SaveChanges() returns 0 but doesn't
Is it possible to use a function import in a where clause in entity
Is it possible to adopt the use of an O/RM like NHibernate or Entity
Is it possible use a MySQL query to perform this kind of check? If
Is this possible to use Ajax.Beginform with update target inside of ajax form. like
It is possible to use AND while querying for Objects in Entity like Post.find(byTitleLikeAndAuthor,
I've a Candidate entity which have an $xmlContent attribute, This attribute is used to
I have several Entity classes. Now I want to use @PostLoad in every entity.
Is it possible to use a constructor with EF entities? I want to add
Is it possible to use hibernate search/lucene to index some entity based on values

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.