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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:41:15+00:00 2026-06-02T06:41:15+00:00

I have three classes: xyz/url/core/datastore/ObjectBase.java xyz/url/core/test/hibernate/BaseClass.java xyz/url/core/test/hibernate/ChildClass.java Their code: ObjectBase package xyz.url.core.datastore; import java.util.Date;

  • 0

I have three classes:

xyz/url/core/datastore/ObjectBase.java
xyz/url/core/test/hibernate/BaseClass.java
xyz/url/core/test/hibernate/ChildClass.java

Their code:

ObjectBase

package xyz.url.core.datastore;

import java.util.Date;

public abstract class ObjectBase {
    private final long  m_id;
    private final long  m_version;

    private final Date  m_creation_time;

    public ObjectBase() {
        this.m_id = 0;
        this.m_version = 0;

        this.m_creation_time = new Date();
    }

    public long get_id() {
        return this.m_id;
    }

    public long get_version() {
        return this.m_version;
    }

    public Date get_creation_time() {
        return this.m_creation_time;
    }
}

BaseClass

package xyz.url.core.test.hibernate;

import java.util.Date;

import xyz.url.core.datastore.ObjectBase;

public abstract class BaseClass extends ObjectBase {

    private final Date  m_another_time;

    public BaseClass() {
        this.m_another_time = new Date();
    }

    public void say_something() {
        final Class<?> my_class = this.getClass();
        final String output = String.format(
                "Hello from the `%s` class! My id is %d!", my_class.getName(),
                this.get_id());
        System.out.println(output);
    }
}

ChildClass

package xyz.url.core.test.hibernate;

public class ChildClass extends BaseClass {
    private String  m_text;

    public ChildClass(final String text) {
        this.m_text = text;
    }

    public void set_text(final String text) {
        this.m_text = text;
    }

    public String get_text() {
        return this.m_text;
    }
}

Currently I use implicit polymorphism; I have one HBM.XML file for the only “concrete” class (ChildClass), named “ChildClass.hbm.xml”:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="xyz.url.core.test.hibernate"
    default-access="field">

    <class name="ChildClass" table="child_class">
        <!-- Attributes of ObjectBase -->
        <id name="m_id" column="id">
            <generator class="increment" />
        </id>

        <version name="m_version" column="version" type="long" />

        <property name="m_creation_time" column="creation_time" type="date" />

        <!-- Attributes of BaseClass -->
        <property name="m_another_time" column="another_time" type="date" />

        <!-- Attributes of ChildClass -->
        <property name="m_text" column="text" type="string" />
    </class>

</hibernate-mapping>

See the above? I aggregate all the attributes of the three classes into one table.

I want to do the same as above, get one table as above (“child_class”), but break it into three HBM.XML files.

I was hoping Hibernate (v4.1) supports some sort of an “import” keyword, so I can create three HBM.XML files, one for each class, and link them all into one.
Unfortunately they got “too smart” and made things a lot more complicated. If I’m wrong, enlighten me please!

Take note that ObjectBase and BaseClass are abstract classes.

Another thing worth mentioning is that when I get an object from the database I know exactly what type it should be, so maybe I should not use “discriminators”…?..

Here is some console output when I test what I currently have, and I wish it stays this way, I mean, one table is created, one table is being fetched when reading (instead of the “join strategy” I’ve read in Hibernate’s docs):

Hibernate: 
    drop table child_class if exists
Hibernate: 
    create table child_class (
        id bigint not null,
        version bigint not null,
        creation_time date,
        another_time date,
        text varchar(255),
        primary key (id)
    )
APR 14, 2012 8:49:47 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
Hibernate: 
    select
        max(id) 
    from
        child_class
Hibernate: 
    /* insert xyz.url.core.test.hibernate.ChildClass
        */ insert 
        into
            child_class
            (version, creation_time, another_time, text, id) 
        values
            (?, ?, ?, ?, ?)

Again, all I want is to break my HBM.XML to three different files so I don’t have to write the same properties in every concrete class’s descriptor. That’s all.

Thank you!

  • 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-02T06:41:17+00:00Added an answer on June 2, 2026 at 6:41 am

    union-subclass is all I needed. Simple, OOP-like inheritance.

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

Sidebar

Related Questions

In my code I have three classes as follows: Forum , Forum::Thread and Forum::Post
I have three classes (House, Room, Address) which are persistent (Mapped with JPA/Hibernate) @Entity
I have three Classes A,B,C. In Class A the code is like this, B*
Have three classes User, Group and Field. Many to many relationship on User /
I have three classes that all have a static function called 'create'. I would
I have three classes; Classes A and B both reference class C . How
I have three classes: ClassA , ClassB , ClassC . ClassC extends ClassB which
If I have three classes class A class B extends A class C extends
I currently have three classes User , UserProfile , and Vendor . User is
I have the following problem. I have three classes, A, B and C. A

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.