spring-data

LazyInitializationException trying to get lazy initialized instance

你。 提交于 2020-05-11 07:42:25
问题 I see the following exception message in my IDE when I try to get lazy initialized entity (I can't find where it is stored in the proxy entity so I can't provide the whole stack trace for this exception): Method threw 'org.hibernate.LazyInitializationException' exception. Cannot evaluate com.epam.spring.core.domain.UserAccount_$$_jvste6b_4.toString() Here is a stack trace I get right after I try to access a field of the lazy initialized entity I want to use: org.hibernate

How to delete items in MongoRepository using query annotation?

最后都变了- 提交于 2020-05-09 20:50:44
问题 I'm using Spring Data with MongoDB using MongoRepository. I was wondering if it is possible do a delete by filter using query annotation. I have been looking here and google and I cannot find any documentation. 回答1: @Query(value="{'id' : $0}", delete = true) public Person deleteById (String id); 回答2: Maybe you can use repository delete queries. Here is an example from documentation: public interface PersonRepository extends MongoRepository<Person, String> { List <Person> deleteByLastname

How to delete items in MongoRepository using query annotation?

别等时光非礼了梦想. 提交于 2020-05-09 20:50:07
问题 I'm using Spring Data with MongoDB using MongoRepository. I was wondering if it is possible do a delete by filter using query annotation. I have been looking here and google and I cannot find any documentation. 回答1: @Query(value="{'id' : $0}", delete = true) public Person deleteById (String id); 回答2: Maybe you can use repository delete queries. Here is an example from documentation: public interface PersonRepository extends MongoRepository<Person, String> { List <Person> deleteByLastname

How to set up liquibase in Spring for multiple data sources?

你离开我真会死。 提交于 2020-05-09 18:53:31
问题 I need to set up liquibase for two datasources in Spring , at the moment it seems that only one liquibase set up is possible and you can choose for which data source. 回答1: If you are using spring boot, here is the setup which can help you: Configuration class: @Configuration public class DatasourceConfig { @Primary @Bean @ConfigurationProperties(prefix = "datasource.primary") public DataSource primaryDataSource() { return DataSourceBuilder.create().build(); } @Bean @ConfigurationProperties

Find all embedded documents from manual reference in mongoDB

╄→гoц情女王★ 提交于 2020-05-09 08:56:36
问题 I use mongodb and spring-boot in a project. I used manual reference to point out a collection, My structure is like follwing. Reel collection { _id : "reel_id_1", name: "reel 1", category :[ { _id : "category_id_1", name: "category 1", videos: ["video_id_1","video_id_2"] } ] } Video collection { _id: "video_id_1", // first document name: "mongo" } { _id: "video_id_2", // seconddocument name: "java" } Java classes are @Document @Data public class Reel { @Id private ObjectId _id; private String

Find all embedded documents from manual reference in mongoDB

时光怂恿深爱的人放手 提交于 2020-05-09 08:55:28
问题 I use mongodb and spring-boot in a project. I used manual reference to point out a collection, My structure is like follwing. Reel collection { _id : "reel_id_1", name: "reel 1", category :[ { _id : "category_id_1", name: "category 1", videos: ["video_id_1","video_id_2"] } ] } Video collection { _id: "video_id_1", // first document name: "mongo" } { _id: "video_id_2", // seconddocument name: "java" } Java classes are @Document @Data public class Reel { @Id private ObjectId _id; private String

Converting MongoDB query to spring

放肆的年华 提交于 2020-04-30 06:26:59
问题 I got a big mongo script and working with spring boot. I need to execute it as either native query or using aggregation framework. I can write lookup , unwind , group in aggregation framework. But I dont know how to write nested $addFields , $map , $reduce , $arrayToObject , $floor , $multiply and $divide . For example, { $lookup: {} //lookup script }, { $unwind // unwind script }, { $addFields: { ans: { $reduce: { input: { $map: { input: "$ans", in: { $objectToArray: "$$this" } } },

Spring part 2 User Role [closed]

倾然丶 夕夏残阳落幕 提交于 2020-04-30 06:23:26
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 days ago . This is the continuation of my first post : User Roles Spring Data Rest Spring security EDIT I added this line in my application.properties: logging.level.org.springframework.security=DEBUG and when I make this previous GET Request, it look like this in the backend: 2020-04-23 07:42:35.563 DEBUG 12596

Spring Mongodb - Cannot write custom Converter for java.time.Period

六月ゝ 毕业季﹏ 提交于 2020-04-20 15:59:53
问题 I'm using Spring Cloud Brixton.SR4 with Spring Data MongoDB. I have a very simple entity: @Document public class Foo{ private Period period; //getter & setter } Because java.time.Period is not supported by jsr310 I'm creating custom converters: class Converters { @Component @WritingConverter static class PeriodToStringConverter implements Converter<Period, String> { @Override public String convert(Period period) { return period.toString(); } } @ReadingConverter @Component static class

PostUpdate hook is not working, while doing batch update

梦想与她 提交于 2020-04-18 05:47:16
问题 I am working with JPA/Hibernate. I am doing bulk-update: Code Snippet: @PersistenceContext private EntityManage entityManager; ... private int update(StudentEntity studentEntity){ CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaUpdate<StudentEntity > criteria = builder.createCriteriaUpdate(StudentEntity.class); Root<StudentEntity> root = criteria.form(StudentEntity.class) setFields(criteria, root, studentEntity) criteria.where(builder.equal(root.get("studentId"),