-->
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.  [ 3 posts ] 
Author Message
 Post subject: Schema generation for custom id generator
PostPosted: Thu Jun 01, 2006 1:43 pm 
Newbie

Joined: Wed May 11, 2005 2:44 pm
Posts: 5
Location: São Carlos - Brazil
Hi all,

I could't figure out how to include my custom id generator, which may delegate work to the seqhilo generator, in the schema generate by hibernate (hbm2dll="create" when creating session factory).
When using de seqhilo directly, its tables are included in the schema as expected.

Thanks.

Here is the code for my generator:

Code:
public class GeneratedIdentifierGenerator implements IdentifierGenerator,
      Configurable {

   /**
    * The delegate parameter specifies the underlying id generator to use.
    */
   public static final String DELEGATE = "delegate";

   private IdentifierGenerator assignedGenerator;

   private IdentifierGenerator delegateGenerator;

   /*
    * (non-Javadoc)
    *
    * @see org.hibernate.id.IdentifierGenerator#generate(org.hibernate.engine.SessionImplementor,
    *      java.lang.Object)
    */
   public Serializable generate(SessionImplementor session, Object object)
         throws HibernateException {
      if (object instanceof BoundedJavaBean) {
         BoundedJavaBean bean = (BoundedJavaBean) object;
         if (bean.getId() != null)
            // The bean already has an id, so tell hibernate it is already
            // assigned
            return assignedGenerator.generate(session, object);
         else
            // Use the real generation strategy if no id was set for the
            // bean
            return delegateGenerator.generate(session, object);
      } else {
         // Use the real generation strategy if the object is not a
         // BoundedJavaBean
         return delegateGenerator.generate(session, object);
      }
   }

   /*
    * (non-Javadoc)
    *
    * @see org.hibernate.id.Configurable#configure(org.hibernate.type.Type,
    *      java.util.Properties, org.hibernate.dialect.Dialect)
    */
   public void configure(Type type, Properties params, Dialect d)
         throws MappingException {
      String generatorName = params.getProperty(DELEGATE);
      if (generatorName == null)
         throw new MappingException(
               "param named \"delegate\" is required for object generation strategy");
      
      // Create the delegate and assigned id generators
      delegateGenerator = IdentifierGeneratorFactory.create(generatorName,
            type, params, d);
      assignedGenerator = IdentifierGeneratorFactory.create("assigned", type,
            params, d);
   }

}



Hibernate version: 3.1.3

Mapping documents:
Code:
        <id name="id" type="long">
            <generator class="com.estatcamp.sci.db.GeneratedIdentifierGenerator">
                <param name="delegate">seqhilo</param>
                <param name="sequence">hi_value_equipment</param>
                <param name="max_lo">100</param>
            </generator>
        </id>
--------------------------
        <id name="id" type="long">
            <generator class="seqhilo">
                <param name="sequence">hi_value</param>
                <param name="max_lo">100</param>
            </generator>
   </id>


Full stack trace of any exception that occurs:

the following error happens because the seqhilo sequence and hi_value table were not created in the database

WARNING: SQL Error: -191, SQLState: S0002
01/06/2006 14:15:21 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Sequence not found: HI_VALUE_EQUIPMENT in statement [select next value for hi_value_equipment from dual_hi_value_equipment]
org.hibernate.exception.SQLGrammarException: could not get next sequence value
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
at org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:53)

Name and version of the database you are using: hsqldb 1.8.0.3


Top
 Profile  
 
 Post subject: fyi..same problem
PostPosted: Wed Jun 21, 2006 12:46 pm 
Newbie

Joined: Tue Mar 16, 2004 11:41 am
Posts: 6
i typically run hibernate with postgres. i just tried out hsqldb (v1.8_0_4) and am encountering the same error:

...
[java] Caused by: java.sql.SQLException: Sequence not found: SEQ_USER in statement [select next value for seq_User from dual_seq_User]
...

am using hibernate v3.1.3.

i use SchemaExport and checked the schema.sql ddl it produced, which seems to include the sequences. but when i connect to the db and look at the ddl, it looks like the sequences are perhaps missing (?).

/ eitan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 1:32 pm 
Newbie

Joined: Wed May 11, 2005 2:44 pm
Posts: 5
Location: São Carlos - Brazil
Hello Eitan,

My problem wasn't the same as yours. Mine I solved by implementing an interface (PersistentIdentifierGenerator) in my id generator. Yours, seems to me, is related to org.hibernate.dialect.HSQLDialect which is not compatible with HSQLDB latest version.
I saw that kinda problem before and it didn't take long for the hibernate folks to update the dialect. So, look for an updated HSQLDialect and your problem might be solved.

Cheers.


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

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.