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

Ask Your Question

Gigaspace 6.5 persisting hierarchy with hibernate

I am using GS 6.5, jdk 1.5. can you describe how a datamodel comprised of a hierarchy (inheritance) of objects is persisted to database using GS POJO approach (not Entry). Should there be one gs.xml and hbm.xml for each concrete class in the hierarchy. I know that the model needs to be flattened. Eg: B implements A, C extends B, D extends C.
Should C define mappings in its C.gs.xml all the fields that are defined in B.gs.xml?

Is there an example of persisting a hierarchy through GS.

SM. 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=2566]{quote}

asked 2008-09-04 09:26:36 -0500

wasefmasood 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

Each class should have its own mapping. If you persist using Hibernate you need to follow Hibernate mapping rules. Shay h4. Attachments


answered 2008-09-04 09:45:09 -0500

shay hassidim gravatar image
edit flag offensive delete link more


1) Is there an example of persisting a hierarchy through GS, using an External Data Source(read-through and write-through, layers are App->GS->Hibernate->RDBMS)? Any links to detailed documentation?

2) Should each gs.xml map all the fields, including its inherited fields?eg: If Class A has field fieldA, and B extends A, should B.gs.xml also contain mapping for fieldA.

3) What mapping strategy should be used. Should there be table per class, table per subclass, or table per hierarchy?

4) How can sequences for Database primary key field be used through GS in this case.


Edited by: s m on Sep 4, 2008 9:10 PM h4. Attachments


wasefmasood gravatar image wasefmasood  ( 2008-09-04 11:11:04 -0500 )edit

1) There is no need for special example.

2) The gs.xml is irrelevant for the persistency. The hbm files or the relevant annotations is what is needed.

3) It is up to you. The best way is to have table per class.

4) See: /[/question/5369/accessing-db-sequence-from-gigaspaces/?comment=5373#comment-5373]


shay hassidim gravatar image shay hassidim  ( 2008-09-05 16:03:57 -0500 )edit

Here are links that can help you very much:


The HBM2GigaSpaces tool is designed to enable a transparent migration of the data access layer from jdbc to space API. The dao source code generation is based on parsing hibernate *.hbm files into GigaSpaces dao objects. Even if you are not using hibernate you will find hibernate-tools beneficial to auto-generate the *.hbm files using a simple JDBC connection of your existing database.

The advantages of using this tool:

* Smoother transition to Space API
* Saving manual coding costs
* Avoiding human errors
* Customizing the entire data layer using template (Velocity) based code generation
* Unified relational mapping for both front-end (spaces) and back-end (async persistence service)

See also this: http://blog.gigaspaces.com/2008/04/23...

Shay h4. Attachments


shay hassidim gravatar image shay hassidim  ( 2008-09-06 09:45:06 -0500 )edit

Shay, you said the gs.xml files are irrelevant. Below are my questions:

  1. Does this mean I should skip generating the *.gs.xml files, and only have hibernate mapping files *.hbm.xml, with <subclass> elements etc?

  2. I would also like to understand why the gs.xml files are irrelevant and the pros and cons here, such as if GS cache performance will be decreased with this approach.

  3. If the *.gs.xml files do need to be generated, what format should the contents of these files be, and how do they reflect the appropriate hibernate strategy. From a previous conversation, my understanding was that GS does not support hibernate mapping strategies (table per class, etc) and all classes need to be flattened out when written to gigaspaces cache.

4.Can I use hibernate features such as one-to-one, one-to-many, component etc for modeling relationships among domain objects? Again, what would be the format of these entries in the corresponding *.gs.xml files.

5,. I think if you can provide sample mappings(*.gs.xml and *.hbm.xml) of two classes A, B where B (has field b1, b2) extends A(has fields a1, a2),that will answer the questions (imho).

I would appreciate a quick response.

Thanks, SM

Edited by: s m on Sep 8, 2008 11:58 AM h4. Attachments


wasefmasood gravatar image wasefmasood  ( 2008-09-08 11:48:01 -0500 )edit

I meant to say that the GigaSpaces mapping (annotations or gx.xml) do not determine the database mapping when using EDS. These are necessary for the space meta data decorations.

The *.hbm.xml files (or relevant annotations) needed for the Hibernate API called by GigaSpaces when using the default open spaces HEDS implementation.

The above means you can map the Space objects to database tables as you wish – GigaSpaces is not aware of this mapping and simply hands the Space object to Hibernate when performing a space write operations and translate space read objects with its template to Hibernate Query to fetch the object data from the database that is loaded into the space.

It is up to you how to Map the Space objects to database tables when persisting these. In most cases , to make this simple , users map a Class to a Database Table.

Shay h4. Attachments


shay hassidim gravatar image shay hassidim  ( 2008-09-08 12:01:05 -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: 2008-09-04 09:26:36 -0500

Seen: 71 times

Last updated: Sep 04 '08