spring-data

How to Store Distance value to SortValues or Entity

孤街浪徒 提交于 2020-05-17 05:44:20
问题 How to Store Distance value to SortValues or Entity using SDE4.0 @Query, and SearchHit "sort": [ { "_geo_distance" : { "codenames.geoLocation" : [ { "lat" : 32.846027, "lon" : -96.84987 } ], "unit" : "mi", "order" : "asc", } } ] 回答1: You have to add a Sort parameter t your repository query, see the documentation for Spring Data Elasticsearch 4 where this is described. In your case you'd need: Sort sort = Sort.by( new GeoDistanceOrder("geoLocation", new GeoPoint(32.846027, -96.84987))

Consider defining a bean named 'entityManagerFactory' in your configuration-Spring boot

守給你的承諾、 提交于 2020-05-16 20:29:48
问题 following is my code Spring boot Entry class @SpringBootApplication @EnableJpaRepositories("com.test.assertmanagementdigital4.repositories") @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}) @ComponentScan("com.test.assertmanagementdigital4") public class AssertManagementDigital4Application { public static void main(String[] args) { SpringApplication.run(AssertManagementDigital4Application.class, args); } } Controller @RestController

Use $strLenCP with Spring Data MongoDB

回眸只為那壹抹淺笑 提交于 2020-05-15 09:34:04
问题 I have this mongodb query db.getCollection('myCollection').aggregate( [{ $project: { length: { $strLenCP: "$prefix" } } }, { $sort: { length: -1 } }] ) that I want to use into a spring java project but I can't manage to write the correct java code (the sort is not the issue). I tried this Aggregation agg = newAggregation(project().andExpression("strLenCP(prefix)").as("prefixLength")); AggregationResults < RequestSettingsWithPrefixLength > results = mongoTemplate.aggregate(agg, RequestSettings

JPA Criteria api join through embedded ID

拈花ヽ惹草 提交于 2020-05-15 03:44:45
问题 I have the following entities: @Entity @Table(name = "place_revision") public class PoiRevision { @OneToMany(mappedBy = "pk.revision", cascade = {CascadeType.ALL}) private Collection<PoiRevisionCategory> categoryMapping; // ... } @Entity @Table(name = "place_revision__category") @AssociationOverrides({ @AssociationOverride(name = "pk.revision", joinColumns = @JoinColumn(name = "place_revision_id")), @AssociationOverride(name = "pk.category", joinColumns = @JoinColumn(name = "category_id")) })

JPA Criteria api join through embedded ID

泄露秘密 提交于 2020-05-15 03:44:04
问题 I have the following entities: @Entity @Table(name = "place_revision") public class PoiRevision { @OneToMany(mappedBy = "pk.revision", cascade = {CascadeType.ALL}) private Collection<PoiRevisionCategory> categoryMapping; // ... } @Entity @Table(name = "place_revision__category") @AssociationOverrides({ @AssociationOverride(name = "pk.revision", joinColumns = @JoinColumn(name = "place_revision_id")), @AssociationOverride(name = "pk.category", joinColumns = @JoinColumn(name = "category_id")) })

Spring Data JPA sorting on nested collection

﹥>﹥吖頭↗ 提交于 2020-05-15 02:05:22
问题 I have the following domain objects: @Entity public class Item { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String name; @OneToMany private List<PropertyDefinition> propertyDefinitions; } @Entity public class PropertyDefinition { @Id private Long id; private final String name; private final String value; } I would like to sort the items for example "title" named PropertyDefinition.value How could I do that with Spring Data JPA? Iterable<Item> items =

Spring Data MongoDB how to assign expiration time programmatically

吃可爱长大的小学妹 提交于 2020-05-14 16:00:05
问题 I couldn't find in any of the Spring-Data documents, what is the way to assign expiration time to a document in MongoDB? 回答1: You can do it using @Indexed annotation's expireAfterSeconds attribute over a field whose type is Date .Roughly: @Document public class SomeEntity { String id; @Field @Indexed(name="someDateFieldIndex", expireAfterSeconds=3600) Date someDateField; // rest of code here } Or by manipulating a MongoTemplate : mongoTemplate .indexOps(SomeEntity.class) .ensureIndex(new

How can a List<Long> references to an ArrayList which has BigInteger values

ぐ巨炮叔叔 提交于 2020-05-14 10:45:29
问题 This method is defined in a JpaRepository and runs a native PostgreSQL query. List<Long> distributorIds = distributorRepository .findDistributorIdsWithChildren(distributorId) It runs with no exception and on runtime I see BigInteger values in returned distributorIds ArrayList instead of Long values . It's same with this question: Bug in Spring Data JPA: Spring Data returns List<BigInteger> instead of List<Long> So how can this bug occur? I mean how JAVA allows this ? If Java doesn't check

spring data JPA - mysql - findById() empty unless findAll() called before

瘦欲@ 提交于 2020-05-13 05:26:27
问题 I'm struggling with this strange error: the findById() method of a CrudRepository returns Optional.empty , unless findAll() is called before when using mysql. e.g. User @Entity public class User { @Id @GeneratedValue private UUID id; public UUID getId() { return id; } } UserRepository public interface UserRepository extends CrudRepository<User, UUID> { } UserService @Service public class UserService { @Autowired private UserRepository userRepository; @Transactional public UUID create() {

LazyInitializationException trying to get lazy initialized instance

守給你的承諾、 提交于 2020-05-11 07:42:49
问题 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