Hibernate初级_v1.0.0

一 XSD

1 问题

① 复合主键

Ⅰ 报错详情
Could not parse mapping document: null (INPUT_STREAM)
org.hibernate.boot.InvalidMappingException: Could not parse mapping document: null (INPUT_STREAM)
	at org.hibernate.boot.jaxb.internal.InputStreamXmlSource.doBind(InputStreamXmlSource.java:46)

Caused by: org.hibernate.boot.MappingException: Unable to perform unmarshalling at line number 7 and column 13. Message: cvc-enumeration-valid: Value 'true' is not facet-valid with respect to enumeration '[false, proxy]'. It must be a value from the enumeration. : origin(null)

Caused by: javax.xml.bind.UnmarshalException: null

报错的意思是使用了未定义的枚举值true,就报错了

Ⅱ 分析

首先看报错的源文件,定位到true这里:

		<composite-id>
            <key-many-to-one class="Xxx" lazy="true" name="Xxxx">
                <column length="32" name="ID">
                    <comment></comment>
                </column>
            </key-many-to-one>
        </composite-id>

找到hibernate-core-5.0.11.Final.jar包,反编译看到文件-org.hibernate.xsd.mapping.legacy-mapping-4.0.xsd里的内容,找到composite-id的规范定义:

<xs:complexType name="CompositeIdType">
        省略
                        <xs:element name="key-many-to-one" type="CompositeKeyManyToOneType"/>
                    </xs:choice>
                    省略
    </xs:complexType>

再找key-many-to-one对应的CompositeKeyManyToOneType的定义,进而找到:

<xs:attribute name="lazy" type="LazyEnum"/>
<xs:simpleType name="LazyEnum">
        <xs:restriction base="xs:token">
            <xs:enumeration value="false"/>
            <xs:enumeration value="proxy"/>
        </xs:restriction>
    </xs:simpleType>

这里发现枚举值不包含true的。因此进行xml验证时报错了

Ⅲ 结论
  • 请不要使用没定义的枚举值

二 属性

1 懒加载

① lazy 依赖顺序

lazy="true"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值