spring-data

Spring Data and MongoDB repository - how to create an update query?

旧城冷巷雨未停 提交于 2020-06-27 11:30:15
问题 I have the following jpa repository: @Query("UPDATE PlayerAccount pa SET pa.password = ?3 WHERE pa.id = ?1 AND pa.password = ?2") @Modifying public int updatePasswordWithValidation(Long playerAccountId, String oldPasswordDB, String encodePassword); Now, i would like to implement a similar update query for a mongoDB repository: @Query("update( { _id: ObjectId(' $1 ') }, { $set: { messageStatus: $2} })") But it doesn't work. any references to how a customized mongo repository update looks like?

SpringFramework: @Transactional(readOnly = true) not working with h2

非 Y 不嫁゛ 提交于 2020-06-27 09:10:26
问题 I am doing transaction testing with the SpringFramework. I have the following classes. UserService.class @Transactional public interface UserService { void add(User user); @Transactional(readOnly = true) User get(String id); @Transactional(readOnly = true) List<User> getAll(); void deleteAll(); void update(User user); } UserServiceImpl.class public class UserServiceImpl implements UserService { // skip some methods @Override public void update(User user) { userDao.update(user); } }

Use Spring Data JPA without Spring Boot application

守給你的承諾、 提交于 2020-06-26 05:32:35
问题 I wanted to know if it is possible to use the Spring Data JPA without the rest of the spring framework? I used Spring Data JPA in a Spring Boot web application for another project and really liked how easy it was to use. Now I have a little project with some friends for a Desktop application without a server and would really like to use Spring Data JPA but I have not found information anywhere on wether it is possible to use it without Beans or the rest of the Spring framework. Is this

Spring Boot Autowiring Repository Always Null [duplicate]

被刻印的时光 ゝ 提交于 2020-06-25 18:00:48
问题 This question already has answers here : Why is my Spring @Autowired field null? (18 answers) Closed 4 years ago . Everytime I go inside my Service Class the Repository does not seem to be Autowired as it keep throwing NullPointerException. Can anyone help check what is it I am missing? Here is my code: DemoApplication.java package com.example; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework

How should I register custom Hibernate 5 data type (BasicType) when Spring Data is used?

此生再无相见时 提交于 2020-06-24 11:48:07
问题 I use Spring Data and decided that I want to create new custom data type that can be used in Hibernate entities. I checked the documentation and choose BasicType and implemented it according to this official user guide. I wanted to be able to register the type under its class name and be able to use the new type in entities without need for @Type annotation. Unfortunately, I’m unable to get reference to the MetadataBuilder or Hibernate configuration to register the new type. Is there a way

Why does Spring get circular dependency issues on one machine and not another?

萝らか妹 提交于 2020-06-24 04:12:29
问题 I have a problem getting a Spring Data based application to run in my environment. I am running Debian, but my co-workers are either using Mac or Ubuntu. I have nothing special set up in my environment variables, and am using the exact same version of Java as others. I have seen this in the logs, suggesting that it is a circular reference problem that is leading to the instantiation failure: nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with

Composite Key and spring-data-jdbc

核能气质少年 提交于 2020-06-23 07:28:31
问题 I have a database which is using composite keys. Is it possible to utilize spring-data-jdbc? I tried the milestone version 1.1M2 where I mapped my entity in the following way: class History { @ID @Embedded private CompositeHistoryID id; } Then in my repository class, I added HistoryRepository extends Repository<History,CompositeHistoryID >{ History findByhId(CompositeHistoryID id) } I traced the SQL, and it did not work. The embedded part worked, but the where clause was not correct. It was

Spring Data Repository @Query - Update and return modified entity

落爺英雄遲暮 提交于 2020-06-21 04:05:11
问题 let's assume we have a Spring Data repository interface with a custom method... @Modifying @Transactional @Query("UPDATE MyEntity SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?1") void markAsSoftDeleted(long id); This method simply sets the deletedAt field of the entity, ok. Is there any way to allow this method to return an updated version of the MyEntity ? Obviously... @Modifying @Transactional @Query("UPDATE MyEntity SET deletedAt = CURRENT_TIMESTAMP WHERE id = ?1") MyEntity

Spring data JPA - Hibernate - TransientObjectException when updating an existing entity with transient nested children

99封情书 提交于 2020-06-17 09:44:07
问题 Following my first question here, the question has changed so I'm creating a new one : org.hibernate.TransientObjectException persisting nested children with CascadeType.ALL I found that my problem was not saving a new entity but updating an existing one. Let's start from the beginning. I have a class called Human which has a list of dogs : @Entity public class Human { @Id @GeneratedValue private Long id; @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}, orphanRemoval = true)

How to query LocalDateTime with LocalDate?

被刻印的时光 ゝ 提交于 2020-06-16 04:56:30
问题 I've got a class which contains an atttribute of java.time.LocalDateTime type. public class MyClass{ // ... private LocalDateTime fecha; // ... } I'm using Spring Data repositories. What I want to accomplish is to query entities according to a date: @Service public interface IRepository extends CrudRepository<MyClass, UUID> { // ... public void deleteByFecha(LocalDate fecha); // ... } But this does not work, as an exception is thrown: org.springframework.dao.InvalidDataAccessApiUsageException