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

Ask Your Question

Customization of initial loading and routing to specific partition

Hi ,

I request, how to implement initial loading and routing to specifi partition.

suppose i have class called Person with property age.

I would like to load all the Person instances of age 25 to specific partition and when ever I write/update Person instance with age 25 it should go to the same partition.

I have implemented the code in the link - How to Customize the initial load , but it is not working. exception occurs while deploying - giving - invalid column - partitionID, total_partitions.

Regards Naveen h4. Attachments


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

asked 2010-09-08 07:15:44 -0500

naveen gravatar image

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

Could you post your Person Bean definition and intial load code?



  1. myPersistence-src.zip

answered 2010-09-08 08:49:18 -0500

seankumar gravatar image
edit flag offensive delete link more


Hi Sean,

Thanks for the reply

The below is the Class Person.

Here the values im not loading from properties file. I have hard coded it.

and below the class file is pu.xml where i have given for initial load entry.

// class file

    @Table(name = "Person")
    @SpaceClass(persist = true, replicate = true)
public class Person extends DefaultHibernateExternalDataSource implements Serializable {

/** The Constant serialVersionUID. */
private static final long serialVersionUID = 614567911968727637L;

        @Column(name = "Id", nullable = false)
private Long id;

@Column(name = "age", nullable = false)
private Long age;

public Person() {

@SpaceId(autoGenerate = false)
        @SpaceIndex(type = SpaceIndexType.BASIC)
        public Long getId() {
            return this.Id;

public void setId(final Long Id) {
            this.Id = Id;

public Long getAge() {
            return age;

public void setAge(Long age) {
            this.age = age;

        public DataIterator initialLoad()
            int partitionID = 1; //Integer.valueOf(props.get(STATICPARTITIONNUMBER).toString()).intValue();
            int totalpartitions= 1; //Integer.valueOf(props.get(NUMBEROF_PARTITIONS).toString()).intValue();
String hquery = "select * from Person where age = 25";

DataIterator iterators = new DataIterator1;
            int iteratorCounter = 0;
            int fetchSize = 100;
            int from =-1;
            int size =-1;
            iteratorsiteratorCounter+ = new DefaultScrollableDataIterator(hquery, getSessionFactory() , fetchSize, from, size);
            return createInitialLoadIterator(iterators);


        public void init(Properties props)
// partitionID = 1; //Integer.valueOf(props.get(STATICPARTITIONNUMBER).toString()).intValue();
// totalpartitions= 1; //Integer.valueOf(props.get(NUMBEROF_PARTITIONS).toString()).intValue();
            //System.out.println("partitionID " + partitionID + " totalpartitions " + totalpartitions);


// pu.xml

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





  1. myPersistence-src.zip
naveen gravatar imagenaveen ( 2010-09-08 09:13:57 -0500 )edit

I see you are implementing the initialLoad method as part of Person class. I assume you are only testing right now and plan to have separate classes for this.

You are expected to pass Person class in the hibernateDataSource bean definition. I am seeing that you are passing org.openspaces.persistency.hibernate.StatelessHibernateExternalDataSource.

HTH Sean h4. Attachments


seankumar gravatar imageseankumar ( 2010-09-08 09:40:55 -0500 )edit

Hi Sean,

Thanks for the reply.

At present I would like to load or route the Person instance to specific space.

I request you to provide me steps to implment this, if what I have done wrong.

or provided me any url where the implementation is done.

Regards Naveen

naveen gravatar imagenaveen ( 2010-09-08 09:48:11 -0500 )edit

Hi Sean,

If I'm not using the DefaultHibernateExternalDataSource and not implmenting the initialLoad and init() methods.

The Person class is loading into space properly while loading. but I would like to load the Person(age = 25) instances from DB, to specific partition, while the remaining instances to other partition.

Regards Naveen h4. Attachments


naveen gravatar imagenaveen ( 2010-09-08 09:55:32 -0500 )edit

Second example on this page is what you need,


Instead of creating an instance of DefaultHibernateExternalDataSource bean in your pu.xml create an instance of EDSInitialLoadExample and inject into space. Something like this,


<bean id="myHibernateDataSource" class="com.test.domain.EDSInitialLoadExample">
    <property name="sessionFactory" ref="sessionFactory"/>

<os-core:space id="space" url="/./mySpace" external-data-source="myHibernateDataSource" />


HTH Sean h4. Attachments


seankumar gravatar imageseankumar ( 2010-09-08 10:49:29 -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


Asked: 2010-09-08 07:15:44 -0500

Seen: 139 times

Last updated: Sep 08 '10