我正在使用Spring Boot 1.3.0.M4和MySQL数据库.
我在使用修改查询时遇到问题,EntityManager在执行查询后包含过时的实体.
public interface EmailRepository extends JpaRepository<Email, Long> {
@Transactional
@Modifying
@Query("update Email e set e.active = false where e.active = true and e.expire <= NOW()")
Integer deactivateByExpired();
}
Run Code Online (Sandbox Code Playgroud)
假设我们在DB中有Email [id = 1,active = true,expire = 2015/01/01].
执行后:
emailRepository.save(email);
emailRepository.deactivateByExpired();
System.out.println(emailRepository.findOne(1L).isActive()); // prints true!! it should print false
Run Code Online (Sandbox Code Playgroud)
public interface EmailRepository extends JpaRepository<Email, Long> {
@Transactional
@Modifying(clearAutomatically = true)
@Query("update Email e set e.active = false where e.active = true and …Run Code Online (Sandbox Code Playgroud) 我希望我的可审计(@CreatedDate和@LastModifiedDate)MongoDB文档可以使用ZonedDateTime字段.
显然,Spring Data不支持这种类型(请看一下org.springframework.data.auditing.AnnotationAuditingMetadata).
框架版本:Spring Boot 2.0.0和Spring Data MongoDB 2.0.0
java.lang.IllegalArgumentException: Invalid date type for member <MEMBER NAME>!
Supported types are [org.joda.time.DateTime, org.joda.time.LocalDateTime, java.util.Date, java.lang.Long, long].
Run Code Online (Sandbox Code Playgroud)
@Configuration
@EnableMongoAuditing
public class MongoConfiguration {
}
Run Code Online (Sandbox Code Playgroud)
public abstract class BaseDocument {
@CreatedDate
private ZonedDateTime createdDate;
@LastModifiedDate
private ZonedDateTime lastModifiedDate;
}
Run Code Online (Sandbox Code Playgroud)
我也试过为ZonedDateTime它创建一个自定义转换器,但Spring Data没有考虑它.该类DateConvertingAuditableBeanWrapper有一个ConversionService在构造函数方法中配置的JodaTimeConverters,Jsr310Converters和ThreeTenBackPortConverters.
@Component
public class …Run Code Online (Sandbox Code Playgroud) 我将Spring Boot与PostgreSQL JDBC 42.2.13和Hibernate 5.3.18.Final一起使用,似乎在IS NULL向 UUID 集合添加检查时,Hibernate/PostgreSQL 无法确定集合的数据类型。
class Element {
@Column
private UUID uuid;
}
Run Code Online (Sandbox Code Playgroud)
@Query("SELECT e FROM Element e WHERE (:uuids) IS NULL OR e.uuid IN (:uuids)")
List<Element> findByUuidIn(@Param("uuids") Collection<UUID> uuids);
Run Code Online (Sandbox Code Playgroud)
elementRepository.findByUuidIn(List.of(UUID.randomUUID())); // works fine!
elementRepository.findByUuidIn(null); // -> Throws exception
Run Code Online (Sandbox Code Playgroud)
org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [OTHER] - [null]
org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [OTHER] - [null]
Run Code Online (Sandbox Code Playgroud)
Caused by: org.postgresql.util.PSQLException: ERROR: could not …Run Code Online (Sandbox Code Playgroud)