SHARE
TWEET

Untitled

a guest Aug 17th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Getter
  2. @Setter
  3. @EqualsAndHashCode(callSuper = true)
  4. @ToString(callSuper = true)
  5. @Table(name = "movie")
  6. @Entity
  7. public class Movie extends BaseEntity {
  8.  
  9.     private String name;
  10.     @Enumerated(EnumType.STRING)
  11.     @Column(columnDefinition = "enum('ACTION','DRAMA','COMEDY','FANTASY','HORROR')")
  12.     private Genre genre;
  13.  
  14.     private BigDecimal budget;
  15.  
  16.     @ManyToMany(mappedBy = "movies")
  17.     private Set<Actor> actors;
  18.  
  19.     public Movie() {
  20.     }
  21. }
  22.      
  23. @Getter
  24. @Setter
  25. @EqualsAndHashCode(callSuper = true, exclude = "movies")
  26. @ToString(callSuper = true, exclude = "movies")
  27. @Table(name = "actor")
  28. @Entity
  29. public class Actor extends BaseEntity {
  30.  
  31.     @Column(name = "first_name")
  32.     private String firstName;
  33.  
  34.     @Column(name = "last_name")
  35.     private String lastName;
  36.  
  37.     @Column(name = "salary")
  38.     private BigDecimal salary;
  39.  
  40.     @ManyToMany(cascade = CascadeType.ALL)
  41.     @JoinTable(
  42.             name = "actor_movie",
  43.             joinColumns = {@JoinColumn(name = "actor_id")},
  44.             inverseJoinColumns = {@JoinColumn(name = "movie_id")}
  45.     )
  46.         private Set<Movie> movies;
  47.  
  48.     public Actor() {
  49.     }
  50. }
  51.      
  52. @Data
  53. @MappedSuperclass
  54. public class BaseEntity implements Serializable {
  55.  
  56.     @Id
  57.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  58.     private Long id;
  59. }
  60.      
  61. @Repository
  62. public interface ActorRepository extends JpaRepository<Actor, Long> {
  63. }
  64.      
  65. @RestController
  66. @RequestMapping("actor")
  67. public class ActorController {
  68.  
  69.     @Autowired
  70.     ActorRepository actorRepository;
  71.  
  72.     @PostMapping
  73.     public Actor save(@RequestBody Actor actor) {
  74.         actorRepository.save(actor);
  75.         return actor;
  76.     }
  77.  
  78.     @GetMapping
  79.     public Iterable<Actor> findAllActors() {
  80.         return actorRepository.findAll();
  81.     }
  82.  
  83.     @GetMapping("{id}")
  84.     public Actor findActor(@PathVariable Long id) {
  85.         return actorRepository.findById(id).orElseThrow(NotFoundException::new);
  86.     }
  87.  
  88.     @PutMapping("{id}")
  89.     public Actor update(@RequestBody Actor actor, @PathVariable Long id) {
  90.         actor.setId(id);
  91.         return actorRepository.save(actor);
  92.     }
  93.  
  94.     @DeleteMapping("{id}")
  95.     public ResponseEntity<Actor> delete(@PathVariable Long id) {
  96.         actorRepository.deleteById(id);
  97.         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
  98.     }
  99. }
  100.      
  101. java.lang.StackOverflowError: null
  102.     at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_172]
  103.     at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[na:1.8.0_172]
  104.     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_172]
  105.     at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) ~[na:1.8.0_172]
  106.     at java.net.URLClassLoader.access$100(URLClassLoader.java:73) ~[na:1.8.0_172]
  107.     at java.net.URLClassLoader$1.run(URLClassLoader.java:368) ~[na:1.8.0_172]
  108.     at java.net.URLClassLoader$1.run(URLClassLoader.java:362) ~[na:1.8.0_172]
  109.     at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_172]
  110.     at java.net.URLClassLoader.findClass(URLClassLoader.java:361) ~[na:1.8.0_172]
  111.     at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_172]
  112.     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_172]
  113.     at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_172]
  114.     at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:737) ~[jackson-databind-2.9.9.jar:2.9.9]
  115.     at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) ~[jackson-databind-2.9.9.jar:2.9.9]
  116.     at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:145) ~[jackson-databind-2.9.9.jar:2.9.9]
  117.     at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:107) ~[jackson-databind-2.9.9.jar:2.9.9]
  118.     at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25) ~[jackson-databind-2.9.9.jar:2.9.9]
  119.     at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727) ~[jackson-databind-2.9.9.jar:2.9.9]
  120.     at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) ~[jackson-databind-2.9.9.jar:2.9.9]
  121.     at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) ~[jackson-databind-2.9.9.jar:2.9.9]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top