spring-data

Rest API and Hibernate. How to add a new record with foreign key?

岁酱吖の 提交于 2019-12-24 11:57:11
问题 I have this object: public class MerchantDetail { private id; private boolean optStatus; private BigDecimal amountDue; @ManyToOne(optional=false) @JoinColumn(referencedColumnName="merchantId") private Merchant merchant; //getters and setters } My table looks like this: `MerchantDetail` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `amountdue` decimal(19,2) DEFAULT NULL, `optstatus` BIT() DEFAULT NULL, `merchant_merchantId` varchar(255) NOT NULL //autogenerated by hibernate ) My current codes are

Spring Data JDBC - One to Many - Kotlin

安稳与你 提交于 2019-12-24 11:28:23
问题 I use spring boot 2.1.1.RELEASE and spring-data-jdbc 1.0.3.RELEASE, Kotlin 1.3.10. I have the following simple class definitions in kotlin: @Table(value = "CUSTOMER") data class Customer( @Id var id: Long?, @Column("NAME") var name: String, @Column("PUBLICATION_NAME") var publicationName: String, @Column("START_DATE") var startDate: String, @Column("END_DATE") var endDate: String, var items: MutableSet<Item> ) @Table(value = "ITEM") data class Item ( @Id var id: Long?, @Column("name") var

elasticserch: org.elasticsearch.client.transport.NoNodeAvailableException: No node available

旧街凉风 提交于 2019-12-24 11:27:48
问题 I have update elasticsearch version from elasticsearch-0.90.7 to elasticsearch-1.3.1 and application was working fine in elasticsearch-0.90.7 but in elasticsearch-1.3.1 getting below exception: 2014-07-31/12:49:22.276 [SimpleAsyncTaskExecutor-4] ERROR step.AbstractStep - Encountered an error executing the step org.elasticsearch.client.transport.NoNodeAvailableException: No node available at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java

Springboot Request method 'POST' not supported

这一生的挚爱 提交于 2019-12-24 09:51:48
问题 I have just started learning Java Spring Boot for REST API development. With below code, GET method is working fine but POST doesn't. @RestController @RequestMapping("/api/users") public class UsersController { @Autowired private UserRepository userRepository; @RequestMapping(method = RequestMethod.GET) public List<User> getAll() { return userRepository.findAll(); } @RequestMapping(method = RequestMethod.POST) public String saveUser() { return "Saved"; } } Tested POST method in Postman app

How to log @Query in PagingAndSortingRepository?

岁酱吖の 提交于 2019-12-24 09:46:25
问题 Is there a way to log some custom @Query method ? Here is example of my code: @Query(value = "SELECT * FROM transfer WHERE char_length(internal_id) = 5 " + "AND internal_id REGEXP '^[0-9]+$' AND project_id = :projectId order by created_at desc limit 1", nativeQuery = true) Transfer findLastWithDefaultOurIdForProject(@Param("projectId") String projectId); It's written in interface that extends spring-data PagingAndSortingRepository . I have tried to log it with adding these lines in property

How do I combine java.util.Map-based mappings with the Spring Data MongoDB annotations (@Id, @Field, …)?

﹥>﹥吖頭↗ 提交于 2019-12-24 09:12:43
问题 I'm going to store a dynamic document with a certain ID. By the dynamic document I mean a map of strings to objects where I don't really care the exact mapping in order to store documents in arbitrary form. However, I would like those documents to be identified by a certain ID specified programmatically, but I would like to have the ID to be declared with org.springframework.data.annotation.Id . Here is the document mapping I expected to work: @Document(collection = "mappings") public final

Spring Data - MongoDB: Unable to retrieve DBRef document that belongs to another database

我的梦境 提交于 2019-12-24 08:33:15
问题 I have a Entity Market(market is stored in a collection within marketDb database) that references Product (stored in a collection product in productDb database ). /*Entity */ class Market { @DBRef (db = "productDb") private Product product; } /**Market is stored in the collection as: */ { "_id": "4f0bc0e6-b6a8-11e6-a04d-080027e9004f", "_class": "com.package.Market", "createdById": "123", "editedById": "123", "name": "Market01", "clientId": NumberLong("1"), "version": NumberLong("1"), "product

Configuring Spring Data Redis with Lettuce for Redis master/slave

家住魔仙堡 提交于 2019-12-24 08:03:08
问题 Using Lettuce, how do we configure Spring Data Redis running on host x at port 6379 and slave running on the same or different host but at port 6380? 回答1: That's a feature which will be included in the upcoming Spring Data Redis 2.1 release. You would configure LettuceConnectionFactory similar to: LettuceClientConfiguration configuration = LettuceClientConfiguration.builder() .readFrom(ReadFrom.SLAVE) .build(); LettuceConnectionFactory factory = new LettuceConnectionFactory(new

Postgres Interval Spring Data Dynamic Parameter not working

我们两清 提交于 2019-12-24 07:53:06
问题 I need to pass in a dynamic param to a Spring Data Postgres Native Query. The param is in an interval expression. At the time of running the code, I verify from pgAdmin that the following returns 1 result only (correctly): select * from recalls_t where created_date <= (now() - interval '18 hour') PROBLEM: 1) In the Spring Data code, the following ?1 notation returns 2 results incorrectly : @Query(value="select * from recalls_t where created_date <= (now() - interval '?1 hour')", nativeQuery

Limiting resultset using @Query anotations

浪尽此生 提交于 2019-12-24 07:38:16
问题 I have a query where I want to limit the size of the resultset. As JPA does not support 'LIMIT', I have been trying to work out the correct approach. I have tried: @Query("SELECT w FROM WardTransaction w WHERE w.visit = :visit ORDER BY w.admissionDateTime DESC").setMaxResults(1) public WardTransaction findCurrent(@Param("visit") Visit visit); Which is not correct. I am just looking for some guidance as to the correct syntax. My repository code is: 回答1: @Query("SELECT w FROM WardTransaction w