spring-data-rest

Hibernate DefaultEntityAliases raises NullPointerException

喜你入骨 提交于 2019-12-04 22:53:34
I'm using Spring Boot, Spring Data REST, Hibernate (5.2.12.Final) and I'm exposing my repositories as REST services. I've a problem with a query that raises a NullPointerException and I don't understand the reason. I'm calling this method via a HTTP request (this is exposed by Spring Data REST). This is the code: @Transactional(readOnly = true) @PreAuthorize("isAuthenticated()") public interface CheckPointRepository extends JpaRepository<CheckPoint, Long> { @Query(value = "SELECT * FROM CheckPoint WHERE (:name IS NULL OR name LIKE CONCAT('%',:name,'%')) ORDER BY name LIMIT 20", nativeQuery =

Spring Data Rest / Spring Hateoas Custom Controller - PersistentEntityResourceAssembler

Deadly 提交于 2019-12-04 22:50:20
问题 I'm attempting to add some additional business logic to the auto-generated endpoints from the RepositoryRestResource. Please see the code below: Resource: @RepositoryRestResource(collectionResourceRel="event", path="event") public interface EventRepository extends PagingAndSortingRepository<Event, Long> { } Controller: @RepositoryRestController @RequestMapping(value = "/event") public class EventController { @Autowired private EventRepository eventRepository; @Autowired private

Extend RepositoryRestExceptionHandler

 ̄綄美尐妖づ 提交于 2019-12-04 20:09:05
I want to extend RepositoryRestExceptionHandler to handle errors in my RestController. I have Validators and working great when using RestRepository but when i use RestController they are not so i did manual Validation like below Errors errors = new BeanPropertyBindingResult(NumberRange, "range"); NumberRangeValidator.validate(NumberRange, errors); if(errors.hasErrors()) { throw new RepositoryConstraintViolationException(errors); } this is resulting in error 500 , what i want to have as result is same as 400 bad request with errors listed in the body . i think i should have to extend the below

How to save many objects in the same request using Spring Boot Data Rest

我的梦境 提交于 2019-12-04 18:20:34
I'm try save a array of an Entity using POST method passing an array for rest resource, but I have an error: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not deserialize instance of br.com.servtech.almox.model.Item out of START_ARRAY token at [Source: org.apache.catalina.connector.CoyoteInputStream@2af1e451; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of br.com.servtech.almox.model.Item out of START_ARRAY token at [Source: org.apache.catalina.connector

Spring JPA Projection including links

落花浮王杯 提交于 2019-12-04 16:24:54
Given a simple model of Event that has a Set of Booking objects: Event: @Entity public class Event { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long eventId; private Date start; private Date end; private String title; @OneToMany(mappedBy="event") private Set<Booking> Bookings; protected Event() { // for JPA } // Getters and setters omitted for brevity } Booking: @Entity public class Booking { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long bookingId; private String title; private String contact; @ManyToOne @JoinColumn(name="event_id", nullable=false) private Event

Spring-data-rest and Spring-jpa [closed]

只谈情不闲聊 提交于 2019-12-04 15:14:30
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center . Closed 7 years ago . data-rest and jpa. I have created one entity with composite keys using @EmbeddedId and repository extends CrudRepository with findById query param when I enter the URL [a link] ( http://localhost:8080/data/person/search/findById?findById=1,2&name=abc ) I'm getting error failed to convert string to Long. Is there

How to use spring.data.rest.enable-enum-translation in Spring Data REST

一笑奈何 提交于 2019-12-04 13:42:43
I'm using Spring Boot 1.5.3, Spring Data REST, HATEOAS, Hibernate. In my model sometimes I'm using enum like: public enum Roles { ROLE_ADMIN, ROLE_USER, ROLE_MANAGER, ROLE_TECH } According to Spring Boot documentation , there is a property that seems useful: # DATA REST (RepositoryRestProperties) spring.data.rest.enable-enum-translation=true I didn't find documentation about how to use that. I found old references where seems I should add something like: roles.role_admin=Amministratore in my messages.properties. That would be cool but it doesn't work and my REST reply contains enum value shown

Adding more information to the HATEOAS response in Spring Boot Data Rest

我只是一个虾纸丫 提交于 2019-12-04 11:43:33
I have the following REST controller. @RepositoryRestController @RequestMapping(value = "/booksCustom") public class BooksController extends ResourceSupport { @Autowired public BooksService booksService; @Autowired private PagedResourcesAssembler<Books> booksAssembler; @RequestMapping("/search") public HttpEntity<PagedResources<Resource<Books>>> search(@RequestParam(value = "q", required = false) String query, @PageableDefault(page = 0, size = 20) Pageable pageable) { pageable = new PageRequest(0, 20); Page<Books> booksResult = BooksService.findBookText(query, pageable); return new

How to update a @ManyToOne relationship with Spring Data REST?

a 夏天 提交于 2019-12-04 11:35:13
问题 I use Spring Data REST with JPA. I have a User entity that has a many to one relationship with another called AccountStatus modeled in a separate RDBMS table. The JSON representation looks like this: { "id": "123" "username": "user1", "accountStatus": { "id": "1", "status": "Active" } } The relationship in the User entity is: @ManyToOne(optional = false) @JoinColumn(name = "account_state") @Getter @Setter private AccountState accountState; Now I try to change the account status using a PATCH

Feign and HAL/resources

半腔热情 提交于 2019-12-04 11:17:50
I've got a server that exposes resources through spring-data-rest and this uses, as far as I understand HAL or HATEOAS. But when I try to use it in combination with Feign, I can't seem to be able to register a Jackson2HalModule that gets picked up. Is there something I have to do to connect the Feign "client" to the new converter? Does it use another ObjectMapper than the one I got here? Code: @Inject public void configureObjectMapper(ObjectMapper mapper, RestTemplate template) { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.registerModule(new