-->
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.  [ 5 posts ] 
Author Message
 Post subject: Setup SequenceStyleGenerator in sping applicationContext
PostPosted: Wed May 02, 2007 11:14 am 
Newbie

Joined: Thu Feb 09, 2006 12:37 pm
Posts: 18
Hi all,
I am trying to set up a new Generator in hibernate so I can use Oracle like sequences in mySQL. (I personal feel identity columns are bad).

So I think I can set up a SequenceStlyeGenerator, point it at my sequence table and its column, and off we go.

The only thing is, how do i do this in a Spring applicationContext.xml, as I am using Spring.

Is it something liks:
<bean id="sessionFactory" blah>
<property name="Generator" class ="org.hibernate.id.enhanced.SequenceStyleGenerator">
<props>
<property key="hibernate.sequence_param">value</property>
<property key="hibernate.initial_param">value</property>
<property key="hibernate.increment_param">value</property>
<property key="hibernate.value_column_param">value</property>
</props>
</property>
</bean>

then in the mapping file:
<id name="OID" column="OID">
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator"/>
</id>

Thanks

G


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 02, 2007 12:16 pm 
Newbie

Joined: Thu Feb 09, 2006 12:37 pm
Posts: 18
Have decided that it should be the following in the mapping file:
<id name="OID" column="OID">
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
<param name="sequence_name">ev_sequence</param>
<param name="initial_value">-9223372036854775808</param>
<param name="increment_size">1</param>
<param name="value_column">CurrentValue</param>
</generator>
</id>

However, it seems that the SequenceStyle generator wont accept a long as its initial value???

org.hibernate.MappingException: could not instantiate id generator
at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:98)
at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:152)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:192)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1143)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1110)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:431)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:251)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:281)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:241)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4336)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:761)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:741)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1307)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1571)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1580)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1560)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NumberFormatException: For input string: "-9223372036854775808"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:459)


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 4:16 am 
Newbie

Joined: Thu May 03, 2007 3:58 am
Posts: 7
Location: London
You want to use something like this:
Code:
<generator class="sequence">
    <param name="sequence">sequense name</param>
</generator>

_________________
Tomas


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 7:30 am 
Newbie

Joined: Thu Feb 09, 2006 12:37 pm
Posts: 18
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator">
<param name="table">table</param>
<param name="sequence">sequence name</param>
<param name="initial">-9223372036854775808</param>
<param name="increment">1</param>
<param name="column">Column name</param>
</generator>

Can not believe I will have to put this in each mapping file.

it works so far as it loads, now to get it to work on inserts.

G


Top
 Profile  
 
 Post subject: deleted
PostPosted: Sun Jan 13, 2008 10:27 am 
Newbie

Joined: Thu Nov 24, 2005 2:19 am
Posts: 10
deleted


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.