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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:08:28+00:00 2026-05-26T03:08:28+00:00

I would like to have something like this be generated from hbm2ddl: ______________ ______________

  • 0

I would like to have something like this be generated from hbm2ddl:

______________    ______________       _______________
|Language    |    |I18N        |       |Test         |
--------------    --------------       ---------------
|iso3_code:PK|----|iso3_code:PK|       |test_id:PK   |
--------------    |i18n_id:PK  |-------|desc_i18n_id |
                  |i18n_text   |     |-|labl_i18n_id |
                  --------------       ---------------

This means more or less that, there is a table language, which holds the iso code and maybe some other info. The i18n table has a foreign key iso3_code on the language table which is also a primary key. The other part of the PK is the i18n_id.
The test table then has two foreign keys on the table i18n on the field i18n_id.

The output of the parsed hbm2ddl should be like this:

public class Test  implements java.io.Serializable {
    private Integer testId;
    private Map<String,String> label = new HashMap<String,String>(0);
    private Map<String,String> description = new HashMap<String,String>(0);

    public Test() {
    }

    public Integer getTestId() {
        return this.testId;
    }

    public void setTestId(Integer testId) {
        this.testId = testId;
    }

    public Map<String, String> getLabel() {
        return label;
    }

    public void setLabel(Map<String,String> label) {
        this.label = label;
    }

    public Map<String, String> getDescription () {
        return description ;
    }

    public void setDescription (Map<String,String> description ) {
        this.description = description ;
    }

}

So now the question is, how has my hbm.xml file to look like to generate this table structure and this class. Even if i can not create all resources fully automatically, I would really like to know how this should be declared. I already got it to work for selects, but not for inserts or updates.

<class name="test.Test" table="test" catalog="testdb">
    <id name="testId" type="java.lang.Integer">
        <column name="test_id" />
        <generator class="native" />
    </id>
    <map name="label" table="i18n" fetch="join" cascade="all">
        <key column="i18n_id" not-null="true" foreign-key="label_id"/>
        <map-key column="iso3_code" type="string"/>
        <element column="i18n_text" type="string"/>
    </map>
</class>

<class name="test.Lang" table="lang" catalog="testdb">
    <id name="iso3Code" type="string">
        <column name="iso3_code" length="4" />
        <generator class="assigned" />
    </id>
</class>

<class name="test.I18n" table="i18n" catalog="testdb">
    <composite-id name="id" class="com.blazebit.test.I18nId">
        <key-property name="i18nId" type="int">
            <column name="i18n_id" />
        </key-property>
        <key-property name="iso3Code" type="string">
            <column name="iso3_code" length="4" />
        </key-property>
    </composite-id>
    <property name="i18nText" type="string">
        <column name="i18n_text" />
    </property>
</class>

I do not really know why the insert does not work, but maybe it is because the I18nId object which should identify a text, can not be generated. In case of this, i would also accept a solution like this:
Map getLabel(){}

But with this solution another problem will arise, the i18n_id can not be set by mysql with auto_increment. It would be possible without hibernate.

Please anybody help me or give a better practice on how to implement this!

  • 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-26T03:08:29+00:00Added an answer on May 26, 2026 at 3:08 am

    I know my question is very old, but probably someone finds this and wants to know how to do that!

    Well my final solution is creating embedded or composite elements within a map. Pretty easy, but you have to know how to do that. Here is an example on how to do that with annotations:

    @Entity
    @Table(name="A")
    public class A implements Serializable{
    
        private Map<Locale, LocalizedA> localized = new HashMap<Locale, LocalizedA>();
    
        @ElementCollection
        @CollectionTable(name = "localized_a")
        @MapKeyJoinColumn(name = "field_name_for_locale")
        public Map<Locale, LocalizedA> getLocalized() {
            return this.localized;
        }
    
        public void setLocalized(Map<Locale, LocalizedA> localized) {
            this.localized = localized;
        }
    
    }
    
    
    @Embeddable
    public class LocalizedA implements java.io.Serializable {
    
        @Column(name = "field_name_for_description")
        public String getDescription() {
            return this.description;
        }
    
        public void setDescription(String description) {
            this.description = description;
        }
    }
    

    I hope this will help someone, if you want an example for hbm.xml files just comment and i will add that.

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

Sidebar

Related Questions

In my routing I would like to have something like not found route handler.
I would like to have an aspx page that contains something like.... <form id=form1
I have already posted something similar here but I would like to ask the
I have an NSString like so: @200hello or @0 something What I would like
I have a file template.txt which contains the following: Hello ${something} I would like
I would just like your feedback on something. Basically I have a value called
I have some MET data I want to validate which would look something like
I have a Silverlight 3 project with something like this: <ItemGroup> <Content Include=Content\image1.png> </Content>
In C#, if you have multiple constructors, you can do something like this: public
I have a dynamically generated form that I would like to submit using Ajax.

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.