Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

Trying to persist to Hibernate: identity generation not happening

Hi there,

I've recently been incrementally 'learning' gigaspaces with the examples while integrating it with Mule and other stuff and am up to putting in the External Data Source, which is Hibernate. I can write Message (simply using the class from the gs examples) into the space and have configured hibernate and have the hEDS plonk it into the database all fine: except when the id column is a PK and meant to be generated. This isn't happening at all, saving with NULL if i remove the @SpaceId annotation and generator in the hbm, or throwing exceptions if @SpaceId is on, or the generator is on in the hbm.

When I was first looking through the doco I came across a page about the Hibernate IG generator but I can't find it anymore. It wasn't the same page in the regular XAP 7.1 doco (about EDS, setting up Hibernate spring beans etc).

Anyway, here's the beans

table create table message ( id int identity(1,1) NOT NULL, info varchar(50) );

message.hbm.xml <hibernate-mapping> <class name="org.openspaces.example.helloworld.common.Message" table="message"> <id name="id" type="int"> <column name="id"/> <generator class="native"/> </id> <property name="info" type="string"> <column name="info"/> </property> </class> </hibernate-mapping>

Message.java @SpaceClass public class Message
{ ... @SpaceRouting @SpaceId public Integer getId() { return id; } ... }

pu.xml ... <os-core:space id="space" url="/./processorSpace" schema="persistent" external-data-source="hibernateDataSource"/> ... <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="mappingResources"> <list> <value>org/openspaces/example/helloworld/common/Message.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop> <prop key="hibernate.cache.use_second_level_cache">false</prop> <prop key="hibernate.connection.url">URL</prop> <prop key="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</prop> <prop key="hibernate.connection.username">AAA</prop> <prop key="hibernate.connection.password">AAA</prop> </props> </property> </bean>

<bean id="hibernateDataSource" class="org.openspaces.persistency.hibernate.DefaultHibernateExternalDataSource">
    <property name="sessionFactory" ref="mySessionFactory"/>
</bean>

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=3538]{quote}

asked 2010-11-08 18:18:08 -0500

updated 2013-08-08 09:52:00 -0500

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

@SpaceId
should be:
@SpaceId (autogenerate=false)

make sure also you set a value within the id field before you write the object.

If you need ID generator see this:
http://www.gigaspaces.com/wiki/display/SBP/GlobalIDGenerator

Shay

answered 2010-11-09 05:40:35 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

Thanks. That page might have been the one.

dapooley gravatar imagedapooley ( 2010-11-09 16:18:43 -0500 )edit

I am having slightly different problem with Identity column.

My database is Sybase. Sybase assigns value to the IDENTITY column automatically and does auto increment for next entry.

When I write an entry to the space and persist to database, the value of the identity field assigned by Sybase is not reflected back to space. Therefore the value of the Identity field in the space is not consistent with that in the database.

Any suggestion how to fix this issue?

jyip gravatar imagejyip ( 2010-11-24 21:35:39 -0500 )edit
shay hassidim gravatar imageshay hassidim ( 2010-11-24 21:39:04 -0500 )edit

can you post the hibernate mapping file and the database table schema?

shay hassidim gravatar imageshay hassidim ( 2010-11-26 02:14:33 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2010-11-08 18:18:08 -0500

Seen: 734 times

Last updated: Nov 09 '10