Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Entity in Spring Data has Atomicinteger property causing issues
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bilal Clarance  
View profile  
 More options Apr 18 2012, 6:33 pm
From: Bilal Clarance <bclara...@gmail.com>
Date: Wed, 18 Apr 2012 15:33:59 -0700 (PDT)
Local: Wed, Apr 18 2012 6:33 pm
Subject: Entity in Spring Data has Atomicinteger property causing issues

Hi,

I am working on a project in which I am persisting legacy documents using
MongoDB. My problem is that the entity that I am stored has a property of
type AtomicInteger. When retrieving an entity from mongo I get this
exception:

Unable to convert value "0" from type 'java.lang.Integer' to type
'java.util.concurrent.atomic.AtomicInteger'; nested exception is
java.lang.IllegalArgumentException: Could not convert number [0] of type
[java.lang.Integer] to unknown target class
[java.util.concurrent.atomic.AtomicInteger]

Of course you cannot cast AtomicInteger to Integer, so I added a setter to
the entity as follows:

    public void setErrorCount(Integer errorCount) {
        this.errorCount.set(errorCount);
    }

This did not solve the issue. I have spent quite a bit of time on google
without luck. If anyone has some ideas I would be grateful.

Thanks
Bilal


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eliot Horowitz  
View profile  
 More options Apr 19 2012, 1:04 am
From: Eliot Horowitz <el...@10gen.com>
Date: Thu, 19 Apr 2012 01:04:44 -0400
Local: Thurs, Apr 19 2012 1:04 am
Subject: Re: [mongodb-user] Entity in Spring Data has Atomicinteger property causing issues
You can add a hook to convert AtomicInteger to Integer
See: http://api.mongodb.org/java/current/org/bson/BSON.html#addEncodingHoo...,
org.bson.Transformer)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bilal Clarance  
View profile  
 More options Apr 19 2012, 5:26 pm
From: Bilal Clarance <bclara...@gmail.com>
Date: Thu, 19 Apr 2012 14:26:57 -0700 (PDT)
Local: Thurs, Apr 19 2012 5:26 pm
Subject: Re: Entity in Spring Data has Atomicinteger property causing issues
Thank you for your answer and I led me to get a some code that would
do the job.
           BSON.addDecodingHook(Integer.class, new Transformer() {
                @Override
                public Object transform(Object object) {
                    if(object instanceof Integer) {
                        Integer integer = (Integer) object;
                        return new AtomicInteger(integer);
                    }
                    return object;
                }
            });

I do have a problem with this though. My entity that I am getting has
other properties that are in fact Integer types so when it pulls those
values out it convert those as well. Could you guide me to somewhere
where I could figure out how to convert based on a specific property
name or based on what type the property of the Entity/Object that I
want to deserialize to from the document;

On Apr 18, 10:04 pm, Eliot Horowitz <el...@10gen.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
schaffer  
View profile  
 More options May 17 2012, 3:38 pm
From: schaffer <stephen.gog...@gmail.com>
Date: Thu, 17 May 2012 12:38:30 -0700 (PDT)
Local: Thurs, May 17 2012 3:38 pm
Subject: Re: [mongodb-user] Entity in Spring Data has Atomicinteger property causing issues

I have a similar issue except I'm using arrays of Atomic Integers.
They are fine writing to the DB and they save as Int32.
However, when I try the solution you suggest I get the following error:

com.mongodb.BasicDBList cannot be cast to
[[Ljava.util.concurrent.atomic.AtomicInteger;
java.lang.ClassCastException: com.mongodb.BasicDBList cannot be cast to
[[Ljava.util.concurrent.atomic.AtomicInteger;

Any ideas on how to overcome this?

Thanks

Sample code:

BSON.addDecodingHook(Integer.class, new Transformer());

AtomicInteger[][] array = (AtomicInteger[][]) dbReturn.get(arrayName);

class Transformer implements org.bson.Transformer {

public Object transform(Object object) {

if (object instanceof Integer) {
Integer integer = (Integer) object;
return new AtomicInteger(integer);

}

return object;


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bryan  
View profile  
 More options May 18 2012, 3:13 am
From: Bryan <bryan.rein...@10gen.com>
Date: Fri, 18 May 2012 00:13:08 -0700 (PDT)
Local: Fri, May 18 2012 3:13 am
Subject: Re: Entity in Spring Data has Atomicinteger property causing issues
The driver deserializes BSON arrays as Lists which can't be cast as a
multi-dimensional array. You'll need to iterate over the List to
populate the array.

On May 17, 12:38 pm, schaffer <stephen.gog...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
schaffer  
View profile  
 More options May 18 2012, 4:20 am
From: schaffer <stephen.gog...@gmail.com>
Date: Fri, 18 May 2012 01:20:16 -0700 (PDT)
Local: Fri, May 18 2012 4:20 am
Subject: Re: Entity in Spring Data has Atomicinteger property causing issues

Thanks. That's good to know.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bryan  
View profile  
 More options May 18 2012, 2:14 pm
From: Bryan <bryan.rein...@10gen.com>
Date: Fri, 18 May 2012 11:14:19 -0700 (PDT)
Local: Fri, May 18 2012 2:14 pm
Subject: Re: Entity in Spring Data has Atomicinteger property causing issues
The drivers try to map BSON types to driver specific native types,
while still providing flexibility to the developer. The encode/decode
hooks work at a low level within the driver, at the wire protocol
level. This gives you some latitude, but the transformation will be
applied across all objects targeted by the hook. Identifying and
modifying more sophisticated objects and structures by name will be
easier to do in your application once the DBObject has been created.

On Apr 19, 2:26 pm, Bilal Clarance <bclara...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »