-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: trouble getting sequence generator via hibernate annotations
PostPosted: Fri Jul 27, 2007 10:57 am 
Newbie

Joined: Wed Jun 06, 2007 3:15 pm
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.