Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an entity with a field of type java.math.BigInteger

public class MyEntity {
  private String id;
  private BigInteger max;
}

I don't have any problem in storing the entity in DB using Spring Data JPA; but when I retrieve the entity, I am getting the following exception

org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate java.math.BigInteger using constructor NO_CONSTRUCTOR with arguments

BigInteger doesn't have a no-argument constructor. Is that a problem? Is there any way to solve this?

I am using spring data couchbase and the complete stack trace is as below

org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate java.math.BigInteger using constructor NO_CONSTRUCTOR with arguments at org.springframework.data.convert.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:64) at org.springframework.data.convert.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:83) at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter.read(MappingCouchbaseConverter.java:203) at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter.read(MappingCouchbaseConverter.java:185) at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter.readValue(MappingCouchbaseConverter.java:725) at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter.access$200(MappingCouchbaseConverter.java:65) at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter$CouchbasePropertyValueProvider.getPropertyValue(MappingCouchbaseConverter.java:78 at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter.getValueInternal(MappingCouchbaseConverter.java:243) at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter$1.doWithPersistentProperty(MappingCouchbaseConverter.java:212) at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter$1.doWithPersistentProperty(MappingCouchbaseConverter.java:206) at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:310) at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter.read(MappingCouchbaseConverter.java:206) at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter.read(MappingCouchbaseConverter.java:185) at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter.read(MappingCouchbaseConverter.java:140) at org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter.read(MappingCouchbaseConverter.java:65) at org.springframework.data.couchbase.core.CouchbaseTemplate.mapToEntity(CouchbaseTemplate.java:606) at org.springframework.data.couchbase.core.CouchbaseTemplate.findById(CouchbaseTemplate.java:298) at org.springframework.data.couchbase.repository.support.SimpleCouchbaseRepository.findOne(SimpleCouchbaseRepository.java:104)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
204 views
Welcome To Ask or Share your Answers For Others

1 Answer

You are right, there is no default converter for BigInteger in Spring Data Couchbase :(

We have custom converters around dates in DatesConverters but that's about it...

We could probably add a few converters in the same line as in the Spring Data Mongo module (like here). Opened the DATACOUCH-234 ticket to track that.

In the meantime, you can use the CustomConverters class instantiated in the AbstractCouchbaseConfiguration to provide your own converters. The simplest is to make a BigInteger-to-String converter for writes, and String-to-BigInteger to read it back.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...