Hi,
I'm trying to reverse engineer our database, and I'm running into two problems.
1) Need to add allocationSize=1 to the sequence generator annotation.
I'm trying to reverse engineer my Oracle db which uses sequences. I get very funky behavior if I don't add allocationSize=1. It starts the numbering at a negative number, and it won't advance past existing rows when the sequence number hits an existing row. It's as if Hibernate is ignoring the sequence. I do see the call to nextval in the logs. Selecting the nextval in a SQL editor returns the correct sequence, but Hibernate never seems to get on track unless I add the allocationSize. The code that is generated is
Code:
@SequenceGenerator(name = "generator", sequenceName = "TYPE_TYPE_ID_SEQ1")
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "generator")
@Column(name = "TYPE_TYPE_ID", unique = true, nullable = false, precision = 22, scale = 0)
public Long getId() {
return this.id;
}
What I'd like to see is
Code:
@SequenceGenerator(name = "generator", sequenceName = "TYPE_TYPE_ID_SEQ1", allocationSize=1)
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "generator")
@Column(name = "TYPE_TYPE_ID", unique = true, nullable = false, precision = 22, scale = 0)
public Long getId() {
return this.id;
}
The definition in my hibernate.reveng.xml file for this table is
Code:
<table name="TYPE_TYPE" class="TypeType">
<primary-key>
<generator class="sequence">
<param name="sequence">TYPE_TYPE_ID_SEQ1</param>
</generator>
<key-column name="TYPE_TYPE_ID" property="id" type="Long"/>
</primary-key>
<column name="TYPE_TYPE_NAME" property="name" type="string"></column>
</table>
Can this be done in hibernate.reveng.xml, or do I need to do this in a reverse engineering strategy? If it has to be done in a strategy, how would I do this? All I've found is articles on how to change the column name.
2) Hibernate seems to be ignoring my names for foreign keys. For example in my hibernate.reveng.xml file I have (some columns deleted fro brevity)
Code:
<table name="METH_STRM" class="MethodStream">
<primary-key>
<generator class="sequence">
<param name="sequence">METH_STRM_ID_SEQ1</param>
</generator>
<key-column name="METH_STRM_ID" property="id" type="Long"/>
</primary-key>
<column name="ATTR_TYPE_ID" property="attributeTypeId" type="Long"></column>
<column name="VAL_TYPE_ID" property="valueTypeId" type="Long"></column>
<column name="DPRD_TYPE_ID" property="dataProductTypeId" type="Long"></column>
</table>
and Hibernate generates
Code:
@Entity
@Table(name = "METH_STRM")
public class MethodStream implements java.io.Serializable {
private Long id;
private Type typeByDprdTypeId;
private Type typeByValTypeId;
private Type typeByAttrTypeId;
...
I would have expected dataProductTypeId or dataProductType, but I'm not sure why it's completely ignoring the name I provided. How do I modify my xml so it doesn't ignore the name?
Any help would be appreciated! Thanks!