logo
down
shadow

Spring Data Rest and collections with unique constraints


Spring Data Rest and collections with unique constraints

By : user2954879
Date : November 22 2020, 10:33 AM
wish of those help In order to customize Spring Data REST (my way to do, I have to speak about with Spring Data REST guys) like following:
Consider we have a exposed repository UserRepository on /users/, you should have at least the following API:
code :
...
/users/{id} GET
/users/{id} DELETE
...
@RestController
@RequestMapping("/users")
public class UserController {

    @Inject
    private UserService userService;

    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    @RequestMapping(method = RequestMethod.DELETE, value = "/{user}")
    public void delete(@Valid @PathVariable("user") User user) {
        if (!user.isActive()) {
            throw new UserNotFoundException(user);
        }
        user.setActive(false);
        userService.save(user);
    }
}
else if (patternAndMethodMatches.isEmpty() && !allowedMethods.isEmpty()) {
    throw new HttpRequestMethodNotSupportedException(request.getMethod(), allowedMethods);
}
import org.springframework.core.Ordered;
import org.springframework.util.Assert;
import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.HandlerMapping;

import javax.servlet.http.HttpServletRequest;

import java.util.List;

/**
 * @author Thibaud Lepretre
 */
public class OrderedOverridingHandlerMapping implements HandlerMapping, Ordered {

    private List<HandlerMapping> handlers;

    public OrderedOverridingHandlerMapping(List<HandlerMapping> handlers) {
        Assert.notNull(handlers);
        this.handlers = handlers;
    }

    @Override
    public HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
        Exception firstException = null;

        for (HandlerMapping handler : handlers) {
            try {
                return handler.getHandler(request);
            } catch (Exception e) {
                if (firstException == null) {
                    firstException = e;
                }
            }
        }

        if (firstException != null) {
            throw firstException;
        }

        return null;
    }

    @Override
    public int getOrder() {
        return -1;
    }
}
@Inject
@Bean
@ConditionalOnWebApplication
public HandlerMapping orderedOverridingHandlerMapping(HandlerMapping requestMappingHandlerMapping,
                                                      HandlerMapping repositoryExporterHandlerMapping) {
    List<HandlerMapping> handlers = Arrays.asList(requestMappingHandlerMapping, repositoryExporterHandlerMapping);
    return new OrderedOverridingHandlerMapping(handlers);
}


Share : facebook icon twitter icon
Spring data neo4j not creating unique indexes/constraints in Grails

Spring data neo4j not creating unique indexes/constraints in Grails


By : Mohamed TOURE
Date : March 29 2020, 07:55 AM
To fix this issue Yes it does rely on the name graphDatabaseService (unfortunately).
Also make sure that your tx class also calls tx.success() not just tx.close()
How to create resource with unique many-to-many relationsships in Spring Data REST?

How to create resource with unique many-to-many relationsships in Spring Data REST?


By : user3256946
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You're slightly misunderstanding or misusing some of the concepts REST and Spring Data REST are based on. Let me start by interpreting the code you presented.
Fundamentals
spring data creates unnecessary unique constraints

spring data creates unnecessary unique constraints


By : Mikhail B
Date : March 29 2020, 07:55 AM
This might help you I have a spring boot application and using following User model class. , If you do not want the uniqueness, use ManyToMany instead.
How to create unique URIs in Spring Data REST repositories?

How to create unique URIs in Spring Data REST repositories?


By : Rishabh Kumar
Date : March 29 2020, 07:55 AM
Does that help The fundamental problem is that you aren't declaring what you seek.
code :
interface StudentRepository extends CrudRepository<Student,Long> {
    List<Student> findByCoursesName(@Param("q") String name);
}
interface CourseRepository extends CrudRepository<Course, Long>{
    List<Student> findByStudentsName(@Param("q") String name);
}
Spring Data: How to update a List of childs with unique constraints

Spring Data: How to update a List of childs with unique constraints


By : user3441498
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am using spring-data to persist data to a mysql db. I have a parent entity that contains a list of child entitys: , I would suggest to use
code :
existingParent.getChilds().clear();
parentRepository.save(existingParent)
existingParent.getChilds().addAll(newChilds);
return parentRepository.save(existingParent);
return existingParent;
Related Posts Related Posts :
  • abount the singleton beans of spring
  • Spring @Autowired Not Working Error Creating Bean Injection Of Autowire dependencies failed
  • Spring-MVC Exception handler returns OK when writing into response
  • My applicationContext.xml is not valid when i deploy my project on tomcat7:org.springframework.beans.factory.parsing.Bea
  • Storing trailing zeroes in database with JPA and Oracle
  • Making specific method non transactional in Spring
  • Spring more than one profile and ${spring.profiles.active}
  • Spring Batch - interrupt thread when job stops
  • Can I use spring AOP to log start and end of a method to help easy debuging
  • How to use different error codes for validation messages?
  • Thymeleaf + Spring Checkboxes not binding
  • Spring Boot: Publish Thymeleaf template without restarting the server
  • How long will Spring 3.x continue to be supported?
  • Spring Security without a login form
  • SOAP UI not finding WSDL depending XSD files in Spring WS Soap Service
  • Spring MVC- Joda datetime error message for invalid date
  • Broadleaf Demosite on JBOSS 7
  • Spring Mongo mapping variable data
  • MySQL and Infinispan - JTA implementation
  • spring boot autoconfiguration with jdbc template autowiring dataSource issue
  • Hibernate and @SessionAttribute
  • DefaultMessageListenerContainer threading issue
  • Good sample spring and hibernate web application book?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org