我正在尝试使用Hibernate Tools eclipse插件/ Maven Hibernate插件生成Hibernate实体pojos。 POJO正在生成,但是我需要@Id来使用下面给出的Oracle序列:
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="patient_sequence")
@SequenceGenerator(name="patient_sequence", sequenceName="PATIENT_SEQ")
@Column(name = "PT_KEY", unique = true, nullable = false, precision = 22, scale = 0)
public Long getPtKey() {
return this.ptKey;
}
我尝试了以下POST中给出的选项: @SequenceGenerator - allocationSize, reverse engineering with Eclipse Hibernate Tools
但它没有考虑oracle序列。它正在生成@id元素,如下所示:
@Id
@Column(name = "PT_KEY", unique = true, nullable = false, precision = 22, scale = 0)
public BigDecimal getPtKey() {
return this.ptKey;
}
请找到hibernate-reverse.xml,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<schema-selection match-schema="DOC" />
<type-mapping>
<sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Long" />
</type-mapping>
<table-filter match-name=".*"></table-filter>
<table name="Patient">
<primary-key>
<generator class="org.hibernate.id.SequenceGenerator">
<param name="sequence">PATIENT_SEQ</param>
</generator>
<key-column name="PT_KEY" />
</primary-key>
</table>
</hibernate-reverse-engineering>
我在这里错过了什么吗?请指教。
答案 0 :(得分:0)
一个小小的调整适用于这两种情况。
将jdbc类型从 NUMERIC 更改为 DECIMAL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<schema-selection match-schema="DOC" />
<type-mapping>
<sql-type jdbc-type="DECIMAL" hibernate-type="java.lang.Long" />
</type-mapping>
<table-filter match-name=".*"></table-filter>
<table name="Patient">
<primary-key>
<generator class="sequence">
<param name="sequence">PATIENT_SEQ</param>
</generator>
<key-column name="PT_KEY" />
</primary-key>
</table>