【问题标题】:Hibernate 4.3 error with mapping file映射文件的休眠 4.3 错误
【发布时间】:2017-10-20 07:29:57
【问题描述】:

我得到一个错误;但是,我无法弄清楚为什么会出现此错误。第一个 class 元素没有给出任何错误,但是第二个 class 元素给出了错误。 (注意:我有其他映射,但它重复了相同的错误,所以我不担心放整个文件)

"元素类型"class"的内容必须匹配

"(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many -to-one|one-to-one|组件|动态组件|属性|any|map|set|list|bag|idbag|array|primitive-array),((join,subclass *)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)"

任何帮助将不胜感激:

代码

<class name = "cdd.model.User" table = "app_user">
    <id name = "userID" column = "user_id" type = "org.hibernate.type.PostgresUUIDType">
        <generator class="org.hibernate.id.UUIDGenerator"/>
    </id>
   
    <property name = "email" column = "email" type = "org.hibernate.type.TextType"/>  
    <property name = "fullName" column = "full_name" type = "org.hibernate.type.TextType"/>
    <property name = "passwordHash" column = "password_hash" type = "org.hibernate.type.TextType"/>
    <property name = "centre" column = "centre" type = "org.hibernate.type.TextType"/>
    <property name = "accessLevel" column = "access_level" type = "org.hibernate.type.IntegerType"/>

    <set name="acceptedQuestions" table="accepted_questions_by_user">
        <key column="user_id"/>
        <many-to-many column="question_id"
                      unique="true"
                      class="cdd.model.Question"/>
    </set>
</class>

<class name = "cdd.model.Category" table ="category" > 
    <!--> Primary Key <!-->  
    <id name ="categoryID" column = "category_id" type = "org.hibernate.type.PostgresUUIDType">
        <generator class = "org.hibernate.id.UUIDGenerator" />
    </id>

    <property name = "title" column = "title" type = "org.hibernate.type.TextType"/>
    <property name = "description" column = "description" type = "org.hibernate.type.TextType" />
    
    <join table = "category" >
        <key column = "category_id"/>
        <many-to-one name="category" column = "category_id" not-null = "true"/>
    </join>
    
    <set name = "questions" table = "category_questions" cascade = "all"  inverse = "true">
        <key column = "category_id" not-null = "true" />
        <one-to-many class = "cdd.model.Question"/> 
    </set>
    
</class>

【问题讨论】:

    标签: java mysql sql-server hibernate mapping


    【解决方案1】:

    在set之后放置join标签部分

    <class name = "cdd.model.User" table = "app_user">
        <id name = "userID" column = "user_id" type = "org.hibernate.type.PostgresUUIDType">
            <generator class="org.hibernate.id.UUIDGenerator"/>
        </id>
    
        <property name = "email" column = "email" type = "org.hibernate.type.TextType"/>  
        <property name = "fullName" column = "full_name" type = "org.hibernate.type.TextType"/>
        <property name = "passwordHash" column = "password_hash" type = "org.hibernate.type.TextType"/>
        <property name = "centre" column = "centre" type = "org.hibernate.type.TextType"/>
        <property name = "accessLevel" column = "access_level" type = "org.hibernate.type.IntegerType"/>
    
     <set name="acceptedQuestions" table="accepted_questions_by_user">
            <key column="user_id"/>
            <many-to-many column="question_id"
                          unique="true"
                          class="cdd.model.Question"/>
     </set>
    </class>
    <class name = "cdd.model.Category" table ="category" > 
    
        <id name ="categoryID" column = "category_id" type = "org.hibernate.type.PostgresUUIDType">
            <generator class = "org.hibernate.id.UUIDGenerator" />
        </id>
    
        <property name = "title" column = "title" type = "org.hibernate.type.TextType"/>
        <property name = "description" column = "description" type = "org.hibernate.type.TextType" />
    
        <set name = "questions" table = "category_questions" cascade = "all"  inverse = "true">
            <key column = "category_id" not-null = "true" />
            <one-to-many class = "cdd.model.Question"/> 
        </set>
    
        <join table = "category" >
            <key column = "category_id"/>
            <many-to-one name="category" column = "category_id" not-null = "true"/>
        </join>
    
    </class>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多