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

Ask Your Question
0

How to persist IMap objects when space persistency based on Hibernate?

Hello,

I'm trying to persist the objects in my space to a database using the HibernateCacheStore. My code is based on the example in: \GigaSpacesEE5.2\examples\Advanced\Data_Grid\Database-Integration\HibernateCacheStore

With this configuration, the space neatly creates a Person table in my database at startup so the config seems to be okay. However, my application writes objects to the space in two ways:

  • Direct using a write() method call
  • Indirect using the IMap interface

When loading entries into the IMap on initialisation of the space, I get the following exception:

com.j_spaces.core.sadapter.SAException: java.lang.RuntimeException: Exception caught while executing load on key: Map.Entry<1,null>
        at com.j_spaces.sadapter.cache.CacheAdapter.getEntry(SourceFile:214)
        at com.j_spaces.obf.fx.a(SourceFile:1747)
        at com.j_spaces.obf.ku.a(SourceFile:4358)
        ...
Caused by: org.hibernate.MappingException: Unknown entity:
        at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:514)
        at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:66)
        ...

I think this is because I didn't provide a Hibernate mapping-file for the objects in the IMap. But the IMap consists of key-value pairs where my key is an Integer and the value is a String. Using the Space Browser I see that in the space these entries are stored as com.j_spaces.map.Envelope classes. I probably need a Hibernate mapping-file for those...

But can someone tell me how to set this up?

This thread was imported from the previous forum.
For your reference, the original is available here

asked 2007-04-12 06:01:02 -0600

martijn gravatar image

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

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

see:
http://www.gigaspaces.com/wiki/display/GS/PersistentSpaceSchema

see the <entity-class> element.

see also:
http://www.gigaspaces.com/wiki/display/GS/Read-ThroughandWrite-ThroughSettingsandConfiguration

The Entity-Class Setting:
when using the Map API users should define the table name (called also Entity) to use when reading value object data.

i think this is what is missing.

shay

answered 2007-04-12 15:43:01 -0600

shay hassidim gravatar image
edit flag offensive delete link more

Comments

Hi Shay,

Thanks for the quick response.

I read the pages you mentioned, but I'm not sure what to use as value for the <entity-class> element. As I understand the docs correctly, it should be the class that is used as key in the IMap? So in my case that would be java.lang.Integer?

martijn gravatar imagemartijn ( 2007-04-13 04:51:00 -0600 )edit

[quote=Martijn]I'm not sure what to use as value for the <entity-class> element. As I understand the docs correctly, it should be the class that is used as key in the IMap? So in my case that would be java.lang.Integer?{quote}

This is the class name of the value in the <key,value> Map pair.

This mapping provides us the ability to access the relevant table when perform a get by key (i.e. Map.get(key) )

moran avigdor gravatar imagemoran avigdor ( 2007-04-16 03:39:02 -0600 )edit

Ok, thanks for the reply. That seems to be working as I'm getting no more errors on that. But now I get the following:

{quote}com.j_spaces.core.sadapter.SAException: java.lang.RuntimeException: no persistent classes found for query class: org.springmodules.javaspaces.entry.AbstractMethodCallEntry; no matching hibernate mapping.{quote}

Can you help me with that as well please? I'm using the javaspaces springmodules for a Master Worker configuration so that's where why this AbstractMethodCallEntry class is created. And there will be more like that...

But actually I don't need those Master Worker classes persisted. So maybe there is a way to tell GigaSpaces what classes to persist and what not ... ?

martijn gravatar imagemartijn ( 2007-04-16 04:16:03 -0600 )edit

Oh and by the way... it still doesn't work. The persisting of the IMap that is.

{quote} com.j_spaces.core.sadapter.SAException: java.lang.RuntimeException: Exception caught while executing load on key: Map.Entry<mymapentry{key=1, value="null" },null=""> at com.j_spaces.sadapter.cache.CacheAdapter.getEntry(SourceFile:214) at com.j_spaces.obf.fx.a(SourceFile:1761) at com.j_spaces.obf.ku.a(SourceFile:4380) ...

Caused by: java.lang.ClassCastException: com.gigaspaces.examples.cache.MyMapEntry at org.hibernate.type.IntegerType.set(IntegerType.java:41) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65) at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514) ... {quote}

I'm getting this exception before first usage of the IMap and the space was newly created so no data in it yet...

martijn gravatar imagemartijn ( 2007-04-16 04:36:01 -0600 )edit

It seems you are writing AbstractMethodCallEntry into the GigaSpaces space. (or performing Map.put). If you need to choose which data is persisted you can turn on the persist flag by extending MetaDataEntry class and calling makeTransient()

If you have classes that are not entries, you will need to flag this property by use of Annotations

import com.gigaspaces.annotation.pojo.SpaceClass; @SpaceClass(persist=false) public class MyNonPersistedObject implements java.io.Serializable { ... }

moran avigdor gravatar imagemoran avigdor ( 2007-04-16 04:36:05 -0600 )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: 2007-04-12 06:01:02 -0600

Seen: 80 times

Last updated: Apr 12 '07