spring-data-mongodb

JAXBElement: providing codec (/converter?) for class java.lang.Class

人走茶凉 提交于 2019-12-23 16:37:03
问题 I have been evaluating to adopt spring-data-mongodb for a project. In summary, my aim is: Using existing XML schema files to generate Java classes. This is achieved using JAXB xjc The root class is TSDProductDataType and is further modeled as below: The thing to note here is that ExtensionType contains protected List<Object> any; allowing it to store Objects of any class. In my case, it is amongst the classes named TSD Module_Name_Here ModuleType and can be browsed here Use spring-data

SpringData MongoDB cannot determine IsNewStrategy during Auditing

蹲街弑〆低调 提交于 2019-12-23 12:13:43
问题 I am trying to enable Auditing using Annotations. My domain class has @Id field that is populated while constructing the object. I have added a java.util.Date field for lastModified and annotated it with @LastModifiedDate. @Document public class Book { @Id private String name; private String isbn; @LastModifiedDate private Date lastModified; public Book(String name) { this.name = name; } } I have enabled auditing in the Spring Configuration XML using <mongo:auditing/>. When I try to save an

Spring data mongodb query for subdocument field

南楼画角 提交于 2019-12-23 10:55:15
问题 I'm using Spring Data's CrudRepository with mongodb and i have some issue to write a query which will select a document with specific subdocument value. Here's an example: { "_id" :, "_class" :, "matchHeader" : { "suspend" : {}, "active" : true, "booked" : true, "eventId" : NumberLong(1009314492), "status" : "" }, "matchInfo" : { } } } i need to select the document with specific eventId field in matchHeader subdocument. i tried to write a function like this findByMatchHeaderEventId(id) but it

How to find collections by its nested object's objectId in Spring Data using repository interface?

蓝咒 提交于 2019-12-23 07:03:02
问题 I have a collection in MongoDB that has items like this one: { "_id" : ObjectId("53e4d31d1f6b66e5163962e3c"), "name" : "bob", "nestedObject" : { "_id" : ObjectId("53f5a623cb5e4c1ed4f6ce67") //more fields... } } Java representation of this item looks following: public class SomeObject { @Id private String id; private String name; private NestedObject nestedObject; //getters and setters } The Repository interface is defined like this: public interface SomeObjectRepository extends

Spring data mongodb application design and data aggregation

老子叫甜甜 提交于 2019-12-23 05:25:11
问题 I was developing a little application with spring data mongo and angularjs . Here is model : public class Lease { @Id private String id; private long created; private Lessor lessor; private Lessee lessee; } public class Payment { @Id private String id; private Integer month; private Integer year; private Long amount; private String leaseId; } I did not embed Payment model as I need it to have an id and edit it in its own form. On the main page of the app it represents a list of leases with

Spring data mongodb application design and data aggregation

…衆ロ難τιáo~ 提交于 2019-12-23 05:25:07
问题 I was developing a little application with spring data mongo and angularjs . Here is model : public class Lease { @Id private String id; private long created; private Lessor lessor; private Lessee lessee; } public class Payment { @Id private String id; private Integer month; private Integer year; private Long amount; private String leaseId; } I did not embed Payment model as I need it to have an id and edit it in its own form. On the main page of the app it represents a list of leases with

@DBRef doesn't pull the Data when use Spring Data Mongo

ぐ巨炮叔叔 提交于 2019-12-23 04:52:30
问题 I used the code from : Error creating bean with name 'personRepository': Invocation of init method failed; nested exception is com.mongodb.util.JSONParseException: and now trying to call Person p = personRepository.findByAddresses_City("London NW1"); System.out.println("PERSON FOR ADDRESS = "+p); I get the null response. Also, below query doesn't pull anything. Query query = new Query(Criteria.where("address.$id").is(2L)); List<Person> l = mongoTemplate.find(query, Person.class); System.out

The value for annotation attribute PageableDefault.size must be a constant expression

ⅰ亾dé卋堺 提交于 2019-12-23 02:29:18
问题 I already went through many links but did not find solution. Here is my code: @Value("${paging.default.pageSize}") public int pageSize; Controller method: @GetMapping() public ResponseEntity<Page<Employee>> getAllEmployee(@PageableDefault(size = pageSize) Pageable pageable) { return countryService.findAllCountries(pageParams, pageable); } The value for annotation attribute PageableDefault.size must be a constant expression 来源: https://stackoverflow.com/questions/56107812/the-value-for

The value for annotation attribute PageableDefault.size must be a constant expression

蹲街弑〆低调 提交于 2019-12-23 02:29:09
问题 I already went through many links but did not find solution. Here is my code: @Value("${paging.default.pageSize}") public int pageSize; Controller method: @GetMapping() public ResponseEntity<Page<Employee>> getAllEmployee(@PageableDefault(size = pageSize) Pageable pageable) { return countryService.findAllCountries(pageParams, pageable); } The value for annotation attribute PageableDefault.size must be a constant expression 来源: https://stackoverflow.com/questions/56107812/the-value-for

Setting createdOn and UpdatedOn automatically

折月煮酒 提交于 2019-12-22 18:07:08
问题 I am playing with spring-data and mongodb. What I am trying to achieve is to automaticaly set createdOn and updatedOn dates when I am creating and/or updating an object. So I basically created a "BaseDocument" that holds createdOn and updatedOn date attributes and created an AbstractMongoDbListener so that i can intercept the document before save (onBeforeSave) and then set those dates. The problem is that if i dont add those dates to the constructor of the class that extends BaseDocument,