Hi there!
I am probably just doing something stupid, but I've tried everything I can think of and searched the forums for related issues and applied their advice, but I haven't been able to resolve my issue. Any help is much appreciated!
I am using Hibernate Annotations in combination with Hibernate Tools Ant rules to try to generate .hbm.xml files with
Code:
<generator class="sequence">
<param name="sequence">widget_id_seq</param>
</generator>
I have read the various forum posts on related issues, and I have tried all the obvious things like added allocationSize and initialValue parameters to my @SequenceGenerator. But when I do so, I always get a "seqhilo" generator instead of "sequence". I have been able to get the generator I want using @org.hibernate.annotations.GenericGenerator, but I'd much rather use @javax.persistence.SequenceGenerator.
I am using the current versions of all the Hibernate code:
hibernate-3.2.4.sp1
hibernate-annotations-3.3.0.GA
hibernate-tools-3.2.0.beta9a
Here is the relevant code I am using:
Widget.java:
Code:
package sandbox;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Version;
import org.hibernate.annotations.Parameter;
@Entity
@org.hibernate.annotations.Proxy
public class Widget {
private Integer _widgetId;
// ...
@Id
@SequenceGenerator(
name="widget_id_seq",
sequenceName="widget_id_seq",
allocationSize=1,
initialValue=1
)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="widget_id_seq")
public Integer getWidgetId() {
return _widgetId;
}
// ...
}
My hibernate.cfg.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">false</property>
<property name="use_outer_join">false</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="generate_statistics">false</property>
<mapping class="sandbox.Widget" />
</session-factory>
</hibernate-configuration>
My Ant rule to generate the .hbm.xml:
Code:
<target name="hbm_xml">
<taskdef
name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="project.path"
/>
<hibernatetool destdir="classes">
<annotationconfiguration
configurationfile="src/hibernate.cfg.xml"
namingstrategy="org.hibernate.cfg.ImprovedNamingStrategy"
/>
<classpath>
<path location="classes" />
</classpath>
<hbm2hbmxml/>
</hibernatetool>
</target>
And the .hbm.xml for the generator that the above code produces:
Code:
<generator class="seqhilo">
<param name="sequence">widget_id_seq</param>
<param name="max_lo">0</param>
</generator>
I have tried replacing PostgreSQLDialect with OracleDialect, just to see if my problem was due to the Postres dialect, but I get the same results.
I can attach a zip of my little Eclipse sandbox project I am using, which is quite minimal and pretty much isolates this problem. It includes all the jars I am using, in case that might have something to do with it.
Again, much thanks for any help you might have. I will use the @org.hibernate.annotations.GenericGenerator for the time being, but I am hoping to replace it with a @javax.persistence.SequenceGenerator soon.
-sullymandias