spring-data

spring data jpa composite key duplicate key record insertion resulting in update

六月ゝ 毕业季﹏ 提交于 2020-01-01 03:32:04
问题 I have one entity having composite key and I am trying to persist it by using spring data jpa repository to mysql databse as given below: @Embeddable public class MobileVerificationKey implements Serializable{ private static final long serialVersionUID = 1L; @Column(name="CUSTOMERID") private Long customerId; @Column(name="CUSTOMERTYPE") private Integer customerType; @Column(name="MOBILE") private Long mobile; @Embeddable public class MobileVerificationKey implements Serializable{ private

Spring-Data mongodb querying multiple classes stored in the same collection

。_饼干妹妹 提交于 2020-01-01 03:23:10
问题 With Spring-Data, you can use the @Document annotation to specify which collection to save the object to. Say I have two classes, Student and Teacher, both persisted into the people collection. When I execute the following code: mongo.find(new Query(), Teacher.class); the result contains both Student and Teacher. Looking in the data created by Spring-Data, each document contains a "_class" field which indicate which class it is persisted from. This is field not used in find as an filter to

Is there a mismatch between Domain-Driven Design repositories and Spring Data ones?

最后都变了- 提交于 2020-01-01 02:28:12
问题 DDD specifies repository per aggregate, but when embracing Spring Data JPA, we can leverage the benefits only when we declare interface per entity. How this impedance mismatch can be resolved? I'm hoping to try out repository interfaces encapsulated within the aggregate repository, is that a OK solution or anything better available? To given an example: Customer is the aggregate root and entities are like Demographics , Identification , AssetSummary etc. where each entity can benefit from

I am trying to use dynamic order by but the list retrieved is not ordered

只愿长相守 提交于 2019-12-31 03:50:09
问题 public List<Series> findSeries(int period, String fieldname, int num) { TypedQuery<Series> query = em.createQuery( "select s from Series s where s.period = ?1 order by ?2", Series.class); query.setParameter(1, period); query.setParameter(2, fieldname); query.setMaxResults(num); return query.getResultList(); } This is the method I am using. I think order by isn't even getting executed, it doesn't give any error even when I pass incorrect fieldname. 回答1: You cannot pass variables as column name

QueryDSL sorting not working with Spring Data

自古美人都是妖i 提交于 2019-12-31 03:35:11
问题 I am currently using JpaSort with Spring Data commons 1.9.1 and Spring JPA 1.7.1. I need to use QueryDSL because JPA does not allow defining the sort for null values. This is my Repository public interface DatasheetRepository extends JpaRepository<Datasheet, Long>, JpaSpecificationExecutor<Datasheet> I am doing this in my Controller: Page<Datasheet> page = m_datasheetRepository.findAll( new PageRequest( pageNumber, pageSize, createSortForDatasheets() ) ); This is what I had with JPA: private

Hibernate Search vs spring-data-solr , spring-data-elasticsearch

孤者浪人 提交于 2019-12-31 03:26:07
问题 I have a spring boot, Spring Data JPA (hibernate) web application and want to introduce text search feature. I understand the following Both hibernate search or spring-data-* can be integrated into my app Hibernate search can work with embedded Lucene or external elastic search. External elastic search/ solr has its own benefits, but I am ok with embedded also to start with. My questions Which library is better for easy development and maintenance. I see many pros and cons of solr vs

Query using “CASE WHEN” statement in WHERE causes QuerySyntaxException: unexpected AST

纵饮孤独 提交于 2019-12-31 01:52:06
问题 I'm trying to make a query using Spring Data, but I cannot make it work: @Query(SELECT t FROM Thing t WHERE name LIKE :name AND CASE WHEN (:minVal <= 0) THEN TRUE ELSE (val <= :minVal) END AND CASE WHEN (:maxVal <= 0) THEN TRUE ELSE (val >= :maxVal) END) Page<Thing> getThings(@Param("name") String name, @Param("maxVal") int maxVal, @Param("minVal") minVal); StackTrace: Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: CASE

Spring Data Elasticsearch: Multiple Index with same Document

孤街浪徒 提交于 2019-12-30 16:37:27
问题 I'm using spring-data-elasticsearch and for the beginning everything works fine. @Document( type = "products", indexName = "empty" ) public class Product { ... } public interface ProductRepository extends ElasticsearchRepository<Product, String> { ... } In my model i can search for products. @Autowired private ProductRepository repository; ... repository.findByIdentifier( "xxx" ).getCategory() ); So, my problem is - I've the same Elasticsearch type in different indices and I want to use the

Spring Data JPA Specification to Select Specific Columns

蓝咒 提交于 2019-12-30 08:30:12
问题 We can select specific columns by writing custom @Query methods in our Repository Interface. However, I don't want to write so many methods for different properties. I tried this, but it returns the entire object all the time. public class MySpecifications { public static Specification<MyInfo> propertiesWithId(final String[] properties, final Object id, final String idProperty) { return new Specification<MyInfo>() { @Override public Predicate toPredicate(Root<MyInfo> root, CriteriaQuery<?>

MongoDB and SpEL Expressions in @Document annotations

五迷三道 提交于 2019-12-30 07:32:29
问题 I am trying to use the SpEL to load the same Document into different collections based on some rules that i have defined. So to start with what i have: -first of all the document: @Document(collection = "#{@mySpecialProvider.getTargetCollectionName()}") public class MongoDocument { // some random fields go in } -second i have the provider bean that should provide the collection name: @Component("mySpecialProvider") public class MySpecialProvider { public String getTargetCollectionName() { //