我从xsd模式生成类。使用Hyperjaxb3指定UUID生成的Id字段
我不知道如何判断一个对象标识符应该是程序中生成的UUID。我的错误是:
休眠:选择NEXTVAL( 'hibernate_sequence') org.hibernate.id.IdentifierGenerationException:com.vsetec.collect.app.generated:该类id必须调用save()之前手动分配。平衡
我的代码是:
<xsd:complexType name="balance">
<xsd:annotation>
<xsd:documentation>Balance Amounts</xsd:documentation>
</xsd:annotation>
<xsd:all>
<xsd:element name="comment" type="longNameString"/>
</xsd:all>
<xsd:attribute name="typeCd" type="referenceCode"/>
<xsd:attribute name="amount" type="xsd:decimal"/>
<xsd:attribute name="currencyCd" type="referenceCode"/>
<xsd:attribute name="dateLoad" type="xsd:date"/>
<xsd:attribute name="historizedOn" type="historizedDate"/>
<xsd:attribute name="id" type="uuidString" minOccurs="0">
<xsd:annotation>
<xsd:appinfo>
<jaxb:property>
<jaxb:javadoc>@hyperjaxb.hibernate.id unsaved-value="null" generator-class="uuid.hex"</jaxb:javadoc>
</jaxb:property>
<hj:id>
<!--<hj:generator generatorClass="uuid"/>-->
<orm:column name="id"/>
<!--<orm:generated-value generator="uuid"/>-->
</hj:id>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
UPD开始 由此,在我的Java如下:
/**
* @hyperjaxb.hibernate.id unsaved-value="null" generator-class="uuid.hex"
*
* @return
* possible object is
* {@link String }
*
*/
@Id
@Column(name = "id", length = 32)
public String getId() {
return id;
}
如果我添加
<orm:generated-value generator="uuid"/>
,它类似于 “有是名UUID没有产生”
如果我添加
<hj:generator generatorClass="uuid"/>
,没有什么是真的添加,无注释添加一个UUID生成器或任何东西。我搜索了“uuid”子字符串,所以我知道。上述错误仍然存在。
我想让Hibernate生成一个标识符作为UUID。该医生说这是与像以下注释实现:
@Id
@GeneratedValue
public UUID id;
的文档是在这里:
它描述了如何UUID类型的字段应注明。我想这是关于如何在Jaxb中映射UUID字段的另一层问题,因此我会首先尝试将其映射为十六进制字符串,例如。但是,如果你对这个问题有一个可行的解决方案,这是远远不寻常的,这对每个人都有用。
UPD结束
与HBM我这样做像下面以前:
<class entity-name="Balance">
<cache usage="read-write"/>
<comment>
Balance Amounts
</comment>
<id name="id" type="string" length="32">
<generator class="uuid"/>
</id>
<property name="currencyCd" type="string" length="32"/>
<property name="amount" type="big_decimal"/>
<property name="comment" type="string" length="255"/>
<property name="historizedOn" type="date"/>
</class>
UPD
我不知道此注释XML映射对应,但工作。它似乎将一个UUID生成器附加到一个字符串字段。我无法说出什么是班级定义,因为我使用了“动态地图”。我的任务是从HBM和动态地图切换到Hyperjaxb和生成的类。
ANSWER (在回答的形式,而在于一个模糊的RTFM风格提示)
<xsd:attribute name="id" type="uuidString" minOccurs="0">
<xsd:annotation>
<xsd:appinfo>
<hj:id>
<orm:column name="id"/>
<orm:generated-value generator="uuid"/>
</hj:id>
<annox:annotate>
<ha:GenericGenerator name="uuid" strategy="uuid2"/>
</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
uuidString应该是36个字符长
PS。还有与大宗插入一个问题(犯罪嫌疑人UUID愚弄,但尚未确定
这个问题归结为:HJ3生成哪些注释以及您希望生成什么? – lexicore
@lexicore谢谢你,我已经更新了这个问题。基本上,我不知道应该生成何种Hibernate/Persistence注释...我唯一的希望是这个问题很常见,它应该有一个简单的解决方案。 – fedd