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

  • Home
  • SEARCH
  • 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 1089129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:10:27+00:00 2026-05-16T23:10:27+00:00

I’ve got a table Category and a table TranslatableText. The category is like this

  • 0

I’ve got a table Category and a table TranslatableText. The category is like this

create table Category (
  id int not null,
  parent_id int default 0,
  TranslatableDescriptionId int default 1,
  primary key(id));

create table TranslatableText (
  id int not null,
  lang enum ('NO','EN','FR'),
  text mediumtext,
  primary key(id, lang));

In my Category entity I’ve defined a mapping:

@Fetch(FetchMode.SUBSELECT)
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
@OneToMany(fetch=FetchType.LAZY)
@JoinColumn(name="TranslatableDescriptionId")
@ForeignKey(name="FK_TranslatableTextId")
private Set<TranslatableText> translatableText;

But when it executes, it tries to access TranslatableDescriptionId, not id. Even if the TranslatableText entity has defined

@Id
@Column(name = "id", nullable = false)
private Integer id;

@Id
@Column(name = "lang", nullable = false)
@Enumerated(EnumType.STRING)
private String lang;

@Column(name = "text", length = 400, nullable = false)
private String text;

The query with the incorrect name selected:

select translatab0_.TranslatableDescriptionId as Translat4_13_1_, translatab0_.id as id1_, translatab0_.lang as Lang1_, translatab0_.id as id22_0_, translatab0_.lang as Lang22_0_, translatab0_.text as Text22_0_ from tblTranslateableText translatab0_ where translatab0_.TranslatableDescriptionId in (‘126’, ‘119’, ‘103’, ‘116’, ‘121’, ‘107’, ‘113’, ‘101’, ‘109’, ‘105’, ‘123’, ‘106’, ‘125’, ‘124’, ‘114’)

If I change the mappings @JoinColumn to read

@JoinColumn(name="TranslatableDescriptionId", referencedColumnName="id")

I get the following error when loading my app:

org.hibernate.MappingException: Unable to find column with logical name: id in org.hibernate.mapping.Table(Category) and its related supertables and secondary tables

For good measure I also tried:

@JoinColumn(name="id", referencedColumnName="TranslatableDescriptionId")

That gave me the error:

org.hibernate.MappingException: Unable to find column with logical name: TranslatableDescriptionId in org.hibernate.mapping.Table(Category) and its related supertables and secondary tables

Any suggestions to what I should do? I really want Category’s translateableText to contain all the translations for its description, so I really want to join Category.TranslatableDescriptionId==TranslatableText.id

UPDATE1:
TranslatableText is used by many entities, so putting in a categoryId in it and reversing the relationship is not an option.

UPDATE2:
I was able to load it saying @JoinColumn(name="id"), but this led to a ClassCastException in Hibernate where it, instead of having an Integer as a key, has an Array containing a single Integer as a key. This fails to be made into a String and thus proper SQL. So it’s probably still not the mapping I want

Cheers

Nik

  • 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-16T23:10:27+00:00Added an answer on May 16, 2026 at 11:10 pm

    This kind of mapping is possible, but not very convenient because you’ll have to manage identity of TranslatableTexts manually (that’s why Hibernate complains about non-mapped column TranslatableDescriptionId):

    public class Category implements Serializable {
        ...
        private Long translatableDescriptionId;
    
        @OneToMany
        @JoinColumn(name="id", referencedColumnName="TranslatableDescriptionId") 
        private Set<TranslatableText> translatableText;
        ...
    }
    

    So, you need to manually assign unique translatableDescriptionIds to all “targets” of TranslatableText (categories, items, folders as you say) and manually set this values as id of TranslatableText before persisting it (you can’t just add TranslatableText into the Set).

    —

    However, the more convenient design is to introduce an intermediate entity to keep the identity of all transalations attatched to a specific target:

    public class Category {
        ...
        @OneToOne(cascade = CascadeType.ALL)
        @JoinColumn(name = "targetId")
        private TranslationTarget target;
    }
    
    public class TranslationTarget {
        @Id @GeneratedValue
        private Long id;
    
        @OneToMany
        @JoinColumn(name = "targetId")
        private Set<TranslatableText> texts;
    }
    

    –

    create table Category (              
      targetId int,
      ...);        
    
    create table TranslationTargets (
      id int primary key
    );      
    
    create table TranslatableText (              
      targetId int not null,              
      lang enum ('NO','EN','FR'),              
      text mediumtext,              
      primary key(targetId, lang)); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.