spring-data

delete key/value from redis - phantom key not deleted

萝らか妹 提交于 2020-08-23 04:23:20
问题 I'm using a Spring Redis repository and I'm puzzled with the delete operation and the phantom key. When a delete is performed, the phantom key is not deleted, is it a normal behaviour ? If yes, is it possible to force a deletion of the phantom key when the original key is deleted from the code. I was expecting that a delete removes the original key AND the associated phantom key. I planned to use to timeToLive feature to ensure that keys not deleted by my application will expire after a while

TransactionRequiredException: no transaction is in progress while using JPAItemWriter

∥☆過路亽.° 提交于 2020-08-22 12:03:53
问题 I am facing weird issue with an application which is a spring boot application. Details Here: The app has a spring batch job which uses JpaItemWriter for performing the writes to the database. Also, the application is configured to use hibernate ItemWriter configuration as follows: @Bean(name = "itemWriter") @StepScope public ItemWriter<Record> itemWriter() { JpaItemWriter<Record> itemWriter = new JpaItemWriter<>(); itemWriter.setEntityManagerFactory(emf); return itemWriter; } The batch job

JPA AttributeConverter not honored in a Spring-data/hibernate query when used in a composite key

这一生的挚爱 提交于 2020-08-22 05:30:52
问题 This is my enum: public enum FooBarType { Foo, Bar; @javax.persistence.Converter public static class Converter implements AttributeConverter<FooBarType, String> { @Override public String convertToDatabaseColumn(FooBarType t) { return t.toString(); } @Override public FooBarType convertToEntityAttribute(String s) { for (FooBarType value : FooBarType.values()) { if (value.name().equalsIgnoreCase(s)) { return value; } } throw new IllegalArgumentException("Invalid value for enum: " + s); } } }

PSQLException: ERROR: syntax error at or near

雨燕双飞 提交于 2020-08-22 04:36:06
问题 I have what I thought was a straight forward relation in JPA. Looks like this. CompanyGroup: @Entity @Table public class CompanyGroup implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @Column(name = "name") private String name; @JoinColumn(name = "companies") @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) private List<Company> companies; } Company: @Entity @Table public class Company implements Serializable {

Spring data deleteBy query doesnt return deleted object

∥☆過路亽.° 提交于 2020-08-08 06:37:53
问题 In Spring-data-mongodb, can we return the single deleted object from query method of repository like below public interface MyRepository extends MongoRepository<MyObject, String>{ Optional<MyObject> deleteByXAndY(String x, String y); } if there will be always single document that's get deleted by above query. I tried it but it throws exception like cant convert Long to MyObject. I think only void, long or List or Stream are supported. Is there any way to achieve what I am trying to do? 回答1:

Spring data deleteBy query doesnt return deleted object

纵然是瞬间 提交于 2020-08-08 06:37:37
问题 In Spring-data-mongodb, can we return the single deleted object from query method of repository like below public interface MyRepository extends MongoRepository<MyObject, String>{ Optional<MyObject> deleteByXAndY(String x, String y); } if there will be always single document that's get deleted by above query. I tried it but it throws exception like cant convert Long to MyObject. I think only void, long or List or Stream are supported. Is there any way to achieve what I am trying to do? 回答1:

JPA Hibernate Dynamic entity mapping & persistence at runtime

浪子不回头ぞ 提交于 2020-08-07 09:49:29
问题 Basically we have a spring boot application that requires that the user can define his/her own set of fields and that these fields should be persisted in their own class/table through JPA/Hibernate at runtime. These classes will be generated dynamically through bytebuddy. All that should be done dynamically without having to restart the application. The Hibernate Dynamic mapping is not an option, since we will be creating new classes entirely and re-map them. I have also considered an EAV

How from Entity to DTO if Entity has an Enum variable?

隐身守侯 提交于 2020-08-05 09:34:31
问题 I'm creating DTO versions of all my entities. I have a problem with an entity that has one Enum value. This is my entity: @Getter @Setter @Table(name = "TIPOS_MOVIMIENTO") @Entity public class TipoMovimiento { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @Column @Convert(converter = TipoMovEnumConverter.class) private TipoMov tipo; public String getTipo() { return tipo.getTipoNombre(); } @OneToMany(mappedBy = "tipoMov") private List<Movimiento> movimientos; No, I

Spring repository method which are returning Java 8 stream doesn't close JDBC connection

大城市里の小女人 提交于 2020-08-02 06:33:42
问题 I have a Spring data repository: @Repository interface SomeRepository extends CrudRepository<Entity, Long> { Stream<Entity> streamBySmth(String userId); } I am calling that method in some Spring bean: @Scheduled(fixedRate = 10000) private void someMethod(){ someRepository.streamBySmth("smth").forEach(this::callSomeMethod); } I am using MySQL database. And when I am running application after some successful method invocations it throws an exception: o.h.engine.jdbc.spi.SqlExceptionHelper : SQL

How to implement DDD using Spring Crud/Jpa Repository

落花浮王杯 提交于 2020-08-02 05:03:46
问题 I want to create an app by implementing DDD using Spring. Let's say I have a business entity Customer and an interface CustomerRepository. Since spring provides CrudRepository and JpaRepository to perform basic CRUD operations and other operations like finder methods by default I want to use them. So my interface becomes @Repository public interface CustomerRepository extends JpaRepository<Customer, Long>{ } But according to DDD, interfaces should be in domain layer and the implementation