Sleep mode for single display

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 am trying to map the " property of the SecretQuestion question to the " contentID "of the content, but Eclipse throws an exception:

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

If I replaced <key column="question" />with <key column="contentID" />, it can start, but displaying incorrect data (in fact, as far as I can see, it maps the question identifier to the content Content identifier)

Does anyone know how to do what I'm trying to achieve here?

Thank.

UPDATE

Okey, after the change, as Pascal said, here is a 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 that I must have a composite primary key for the secret query table, which I do not need :(

UPDATE

I will give an example to clarify what I'm 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

4, 5, 6 4, 5, 6.

+3
1

, Hibernate ( , ), , contentID, ContentGetter, .

+1

Source: https://habr.com/ru/post/1763014/


All Articles