Quantcast
Channel: Spring Community Forums - NoSQL
Viewing all articles
Browse latest Browse all 128

Spring data can not serialize entity on find and remove execution

$
0
0
I'm using spring-data-mongodb-1.2.0.RELEASE. I have two classes A and B where B has a reference to A and it is annotated with @DBRef.

Class A:

Code:

@Document(collection = "a")
public class A {
@Id
public String id;

/** The TicketGrantingTicket this is associated with. */
@Field
public String name;

public A(String id, String name) {
    this.id = id;
    this.name = name;
}
}

Class B:

Code:

@Document(collection = "b")
public class B {

@Id
public String id;

@Field
public String name;

@DBRef
@Indexed
public A a;

public B(String id, String name, A a) {
    super();
    this.id = id;
    this.name = name;
    this.a = a;
}
}

After creating and associating A and B instances:

Code:

A a1 = new A("a-2", "a-2");
mongoOperations.insert(a1);

B b1 = new B("b-2", "b-2", a1);
mongoOperations.insert(b1);

I'm able to execute the next query:

Code:

B fromDB = mongoOperations.findOne(Query.query(Criteria.where("a").is(a1)), B.class);
But(!!!), when I'm executing findAndRemove:

Code:

fromDB = mongoOperations.findAndRemove(Query.query(Criteria.where("a").is(a1)), B.class);
I'm getting this:

java.lang.RuntimeException: json can't serialize type : class org.jasig.cas.ticket.registry.entities.A at com.mongodb.util.ClassMapBasedObjectSerializer.ser ialize(ClassMapBasedObjectSerializer.java:77) at com.mongodb.util.JSONSerializers$MapSerializer.ser ialize(JSONSerializers.java:307) at com.mongodb.util.ClassMapBasedObjectSerializer.ser ialize(ClassMapBasedObjectSerializer.java:79) at com.mongodb.util.JSON.serialize(JSON.java:56) at com.mongodb.util.JSON.serialize(JSON.java:41) at com.mongodb.BasicDBObject.toString(BasicDBObject.j ava:83) at java.lang.String.valueOf(String.java:2826) at java.lang.StringBuilder.append(StringBuilder.java: 115) at org.springframework.data.mongodb.core.MongoTemplat e.doFindAndRemove(MongoTemplate.java:1392) at org.springframework.data.mongodb.core.MongoTemplat e.findAndRemove(MongoTemplate.java:572) at org.springframework.data.mongodb.core.MongoTemplat e.findAndRemove(MongoTemplate.java:568)

Does someone have an idea why?

Viewing all articles
Browse latest Browse all 128

Trending Articles