0

I am trying to write to gemfire server in region 'trade'. My class is like :

public class TradeDetails{
String exchange;
String Product;
String Account;
String Quantity;
//getter and setter }

I have deployed the jar in the gfsh console. The query I am running on gfsh console is

put --key=1 --value=('exchange':'xyz','Product':'abc','Account':'xyz','Quantity':'123L') --region=/trade --value-class=model.TradeDetails

But I am getting an error

Couldn't convert JSON to Object of type class model.TradeDetails.

What could be the cause?

Gediminas Masaitis
  • 3,172
  • 14
  • 35
Pratik Kumar
  • 81
  • 10
  • I think your JSON may be invalid. Could you try something like: `--value='{"exchange":"xyz",....}'`? Note in particular the enclosing `{...}` braces. – Jens D Mar 04 '16 at 15:33
  • I tried put --key=1 --value={"exchange":"xyz","Product":"abc","Account":"xyz","Quantity":"123L"}' --region=/trade --value-class=model.TradeDetails But it too didnt work – Pratik Kumar Mar 05 '16 at 19:22

1 Answers1

0

Well, according to the GemFire documenation, your Gfsh put command appears to be correct...

put --key=1 --value=('exchange':'xyz','Product':'abc','Account':'xyz','Quantity':'123L') --region=/trade --value-class=model.TradeDetails

However, your key value 1 is a bit suspect. If you used a key constraint of java.lang.Long on your "/trade" Region then you also need to specify the --key-class option on the put.

I was able to successfully perform the following...

$ gfsh
    _________________________     __
   / _____/ ______/ ______/ /____/ /
  / /  __/ /___  /_____  / _____  / 
 / /__/ / ____/  _____/ / /    / /  
/______/_/      /______/_/    /_/    v8.2.0

Monitor and Manage GemFire

gfsh>connect
Connecting to Locator at [host=localhost, port=10334] ..
Connecting to Manager at [host=10.99.199.3, port=1099] ..
Successfully connected to: [host=10.99.199.3, port=1099]


gfsh>list members
Member Count : 1
Coordinator  : SpringGemFireDataServer (10.99.199.3(SpringGemFireDataServer:77179)<v0>:47312)

         Name           | Id
----------------------- | ----------------------------------------------------
SpringGemFireDataServer | 10.99.199.3(SpringGemFireDataServer:77179)<v0>:47312


gfsh>describe member --name=SpringGemFireDataServer
Name        : SpringGemFireDataServer
Id          : 10.99.199.3(SpringGemFireDataServer:77179)<v0>:47312
Host        : 10.99.199.3
Regions     : People
PID         : 77179
Groups      : 
Used Heap   : 229M
Max Heap    : 3641M
Working Dir : /Users/jblum/pivdev/spring-data-gemfire-tests-workspace/spring-data-gemfire-tests/target
Log file    : /Users/jblum/pivdev/spring-data-gemfire-tests-workspace/spring-data-gemfire-tests/target
Locators    : localhost[10334]

Cache Server Information
Server Bind              : localhost
Server Port              : 40404
Running                  : true
Client Connections       : 0


gfsh>list regions
List of regions
---------------
People


gfsh>describe region --name=/People
..........................................................
Name            : People
Data Policy     : partition
Hosting Members : SpringGemFireDataServer

Non-Default Attributes Shared By Hosting Members  

 Type  | Name | Value
------ | ---- | -----
Region | size | 0


gfsh>
gfsh>put --region=/People --key=1 --key-class=java.lang.Long --value=('firstName':'Jon','lastName':'Doe') --value-class=org.spring.data.gemfire.app.beans.Person
Result      : true
Key Class   : java.lang.Long
Key         : 1
Value Class : org.spring.data.gemfire.app.beans.Person

Value
------
<NULL>

gfsh>
gfsh>describe region --name=/People
..........................................................
Name            : People
Data Policy     : partition
Hosting Members : SpringGemFireDataServer

Non-Default Attributes Shared By Hosting Members  

 Type  | Name | Value
------ | ---- | -----
Region | size | 1

Note, my "/People" Region has a key type of java.lang.Long and value type of org.spring.data.gemfire.app.beans.Person.

Although, when I attempted to read "Jon Doe" back out, Gfsh puked...

gfsh>get --region=/People --key=1 --key-class=java.lang.Long --value-class=org.spring.data.gemfire.app.beans.Person
Exception occurred. null

However, I did go onto create a (Spring Boot-based) GemFire client cache application (with a base configuration of SpringGemFireClient) that pulled the Person back out successfully.

Person is [Jon Doe]

You might try annotating your model.TradeDetails application domain type with the Jackson mapping annotations, though I am not certain Gfsh actually uses them to perform the mapping since I think (when I lasted checked) Gfsh was not using Jackson. But, it wouldn't hurt either. Either way.

Note, my Server was started with this SpringGemFireDataServer, which is based on SpringGemFireServer.

Hope this helps (a little :-).

Cheers! John

John Blum
  • 7,381
  • 1
  • 20
  • 30
  • Just a quick update... I modified my example and configured the "/People" Region with (PDX) read-serialized set to true as well as used Jackson's mapping annotations in my application domain model type (org.spring.data.gemfire.app.beans.Person). Neither modification made a difference and I still encounter the "Exception occurred. null" error in Gfsh. However, the Spring Boot-based cache client application continues to access the person (Jon Doe) in the "/People" Region on the server just fine. – John Blum Mar 04 '16 at 22:44
  • And yet, another quick update... as further proof that the data/person (Jon Doe) does exist, I am able to query (with OQL) the person in Gfsh like so... gfsh>query --query="SELECT * FROM /People WHERE lastName = 'Doe'" Result : true startCount : 0 endCount : 20 Rows : 1 name | firstName | lastName ------- | --------- | -------- Jon Doe | Jon | Doe NEXT_STEP_NAME : END – John Blum Mar 04 '16 at 22:47
  • It still doesnt work after adding --key-class=java.lang.Long – Pratik Kumar Mar 05 '16 at 19:23
  • Basically what I wanted to do is add a Table 'TradeDetails' with columns exchange,Product,Account,Quantity. But what I understood is that we can add only in form of map(key,value). Is there any way to add table data in cache – Pratik Kumar Mar 05 '16 at 19:27
  • GemFire is a Key/Value store, so NO. But, essentially, you can have a strongly-typed Region (i.e. Region tied to a specific application domain object type, e.g. TradeDetails). The properties (exchange, product, account, quantity, etc) of TradeDetails can be indexed and used as a predicate in an OQL (query) statement like any column in a RDBMS. If yor data is serialized as PDX, it is also a simple matter to add/remove properties (columns). However, GemFire is not a true columnar store like, say Cassandra. – John Blum Mar 14 '16 at 01:05