Comments (6)
If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete sample that reproduces the problem. Looking at the example, AttributeEntity
is missing so we do not have a complete example here.
You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
from spring-data-commons.
A simple demo. Look at class DemoApplication. There is also a docker-compose file, that starta a Mongo instance.
demo.zip
package com.example.demo;
import com.example.demo.DemoApplication.Format.RecursiveFormat;
import com.example.demo.DemoApplication.Format.StaticFormat;
import java.util.Random;
import org.bson.json.JsonWriterSettings;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.mapping.Document;
@SpringBootApplication
public class DemoApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Document("attributes")
public record Attribute(@Id ObjectId id, Format format) {}
public sealed interface Format {
public record RecursiveFormat(Format format) implements Format {}
public record StaticFormat(String format) implements Format {}
}
@Autowired
private MongoTemplate mongoTemplate;
@Override
public void run(final String... args) throws Exception {
var id = new ObjectId();
var attribute = new Attribute(id, new RecursiveFormat(new RecursiveFormat(new RecursiveFormat(new StaticFormat("FOO")))));
mongoTemplate.save(attribute);
System.out.println("Saved: " + attribute);
var document = mongoTemplate.execute("attributes", collection -> collection.find(new org.bson.Document("_id", id)).first());
System.out.println("Reading document as a org.bson.Document" + document.toJson(JsonWriterSettings.builder().indent(true).build()));
var readAttribute = mongoTemplate.findById(id, Attribute.class);
System.out.println("Reading document as Attribute: " + readAttribute);
}
}
Logs:
Saved: Attribute[id=65c1423f0fbf892135c39397, format=RecursiveFormat[format=RecursiveFormat[format=RecursiveFormat[format=StaticFormat[format=FOO]]]]]
Reading document as a org.bson.Document{
"_id": {
"$oid": "65c14305757b715020f450cd"
},
"format": {
"format": {
"format": {
"format": {
"format": "FOO",
"_class": "com.example.demo.DemoApplication$Format$StaticFormat"
},
"_class": "com.example.demo.DemoApplication$Format$RecursiveFormat"
},
"_class": "com.example.demo.DemoApplication$Format$RecursiveFormat"
},
"_class": "com.example.demo.DemoApplication$Format$RecursiveFormat"
},
"_class": "com.example.demo.DemoApplication$Attribute"
}
Reading document as Attribute: Attribute[id=65c1423f0fbf892135c39397, format=RecursiveFormat[format=null]]
from spring-data-commons.
So, when fetching the object with mongTemplate.execute
, the returned object looks perfectly fine. However, when findById
is used, it does not!
from spring-data-commons.
@G0dC0der thanks for the reproducer - we'll have a look.
from spring-data-commons.
So apparently this is an issue when the mapping requires objects to be created via an argument constructor. Things works as expected when switching RecursiveFormat
to a class
having a noargs constructor.
from spring-data-commons.
The issue stems from PersistentEntityParameterValueProvider
which considers the constructor Parameter
to belong to the parent type and then returning null
for the actual value.
from spring-data-commons.
Related Issues (20)
- Release 3.1.11 (2023.0.11)
- Release 3.2.5 (2023.1.5)
- Release 3.3 RC1 (2024.0.0)
- Cache result of `RepositoryInformationSupport.getQueryMethods()` HOT 5
- Aligning internal caches with core framework patterns.
- Bug in AbstractPageRequest::hashCode
- Window.positionAt should always return exact position of element HOT 1
- Investigate potential solution to pass in additional options for scroll behaviour.
- More precise type information of factory bean definitions
- Release 3.1.12 (2023.0.12)
- Release 3.2.6 (2023.1.6)
- Release 3.3 GA (2024.0.0)
- Refine null-safety with NullAway build-time checks
- Allow custom bean name generator for repository HOT 2
- Unresolved self-recursive generics comparison causes `StackOverflowError` HOT 1
- Why is PersistentEntity created for types defined in CustomConversions? HOT 7
- members of Interface TypeInformation are null when AOP and Data Rest are enabled and a bean is marked @Lazy
- Apply Kotlin Value Class unboxing to generated Property Accessors
- Introduce `Parameter.getRequiredName()` and `Parameter.hasName()`
- `RepositoryConfigurationDelegate.getRepositoryInterface(…)` constructs `ResolvableType` with improper generics size
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-data-commons.