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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:38:39+00:00 2026-05-18T01:38:39+00:00

I have two tables: <class name=Content table=language_content lazy=false> <composite-id> <key-property name=contentID column=contentID/> <key-property name=languageID

  • 0

I have two tables:

<class name="Content" table="language_content" lazy="false">
    <composite-id>  
        <key-property name="contentID" column="contentID"/>  
        <key-property name="languageID" column="languageID"/>           
    </composite-id> 
    <property name="Content" column="Content" />
</class>

and

<class name="SecretQuestion" table="secretquestions" lazy="true">
    <id name="questionID" type="integer" column="QuestionID">
        <generator class="increment"></generator>
    </id>
    <property name="question" column="Question"/>
    <property name="isUsing" column="IsUsing"/>
    <bag name="contents" inverse="true" cascade="all,delete-orphan">
        <key column="question" />
        <one-to-many class="Content" />
    </bag>
</class>

I’m trying to map the “question” property of SecretQuestion to the “contentID” property of Content but Eclipse throwing out an exception:

org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.sms.model.entity.SecretQuestion.contents#1]

If I replace the <key column="question" /> with <key column="contentID" />, it can run but mapping the wrong data (actually, as far as I see, it maps the questionID with the contentID of Content)

Anyone know how to do what I’m trying to achieve here?

Thanks.

UPDATE

Okey, after modifying as Pascal said, here is the new error:

javax.servlet.ServletException: org.hibernate.MappingException: Foreign key (FKB65C9692FCD05581:language_content [contentID,languageID])) must have same number of columns as the referenced primary key (secretquestions [QuestionID])

This error means I have to have a composite primary key for secretquestions table which I don’t want 🙁

UPDATE

I will give an example to clearer what I trying to do:

Table SecretQuestion
questionID* question answer
1           4        a
2           5        a
3           6        a

Table Content
contentID* languageID* content
1          1           a
1          2           b
2          1           c
2          2           d
3          1           e
3          2           f
4          1           g
4          2           h
5          1           i
5          2           j
6          1           k
6          2           l

Now I want to map question 4, 5, 6 to content ID 4, 5, 6.

  • 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-18T01:38:40+00:00Added an answer on May 18, 2026 at 1:38 am

    Looks like this approach cannot work and is not supported by Hibernate (the Content table have composite primary key while I want to mapping it to only one field in the Question table), thus I use a workaround that I only map the question to the contentID and I use a ContentGetter class that will get the content depend on the languageID.

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

Sidebar

Related Questions

I have two tables, one Company and one Employee: class Company(models.Model): name = models.CharField(max_length=60)
I have xpath page.search(//table[@class='campaign']//table) which returns two tables. I need to choose only first
I have two tables, for example: Table A Table B ======= ======= Name |
I Have two tables: Users and News. Table News has columns id, name, createdby,
i have two tables both are related with primary-foreign key ralation and i have
I have two tables, the first has a primary key that is an identity,
I have the following 2 entities: @Entity(name = Employee) @Table(name = EMPLOYEE) public class
I have the following models: # Group for Key/Value pairs class Group(models.Model): name =
We have 2 tables: Table Authority: public class Authority { public int ID {get;set;}
i have two tables products and reviews each product has several reviews linked by

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.