Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
{
"id": "50f06778-83f3-3359-8bc5-cc3d0bdf582d",
"name": "Hibernate one to many mapping example",
"description": "",
"order": [
"15826d80-cf0a-78c9-1acf-36fef67d89fc",
"095e803e-c84e-6e66-c785-83930184de23",
"1086cdf7-fb9e-305a-1118-b4a1e3335453",
"df740598-560e-5b22-8c65-f719411d1d24"
],
"folders": [],
"folders_order": [],
"timestamp": 1569687636029,
"owner": "2037757",
"public": false,
"requests": [
{
"id": "095e803e-c84e-6e66-c785-83930184de23",
"headers": "Content-Type: application/json\n",
"headerData": [
{
"key": "Content-Type",
"value": "application/json",
"description": "",
"enabled": true
}
],
"url": "localhost:8080/v1/posts?page=0&size=3&sort=createdAt,desc",
"queryParams": [
{
"key": "page",
"value": "0",
"equals": true,
"description": "",
"enabled": true
},
{
"key": "size",
"value": "3",
"equals": true,
"description": "",
"enabled": true
},
{
"key": "sort",
"value": "createdAt,desc",
"equals": true,
"description": "",
"enabled": true
}
],
"preRequestScript": null,
"pathVariables": {},
"pathVariableData": [],
"method": "GET",
"data": null,
"dataMode": "params",
"version": 2,
"tests": null,
"currentHelper": "normal",
"helperAttributes": {},
"time": 1569689480899,
"name": "Retrieve all posts",
"description": "",
"collectionId": "50f06778-83f3-3359-8bc5-cc3d0bdf582d",
"responses": []
},
{
"id": "1086cdf7-fb9e-305a-1118-b4a1e3335453",
"headers": "Content-Type: application/json\n",
"headerData": [
{
"key": "Content-Type",
"value": "application/json",
"description": "",
"enabled": true
}
],
"url": "localhost:8080/v1/posts/1/comments",
"queryParams": [],
"pathVariables": {},
"pathVariableData": [],
"preRequestScript": null,
"method": "POST",
"collectionId": "50f06778-83f3-3359-8bc5-cc3d0bdf582d",
"data": [],
"dataMode": "raw",
"name": "Create comment",
"description": "",
"descriptionFormat": "html",
"time": 1569689148814,
"version": 2,
"responses": [],
"tests": null,
"currentHelper": "normal",
"helperAttributes": {},
"rawModeData": "{\n\t\"text\": \"it's nice post\"\n}"
},
{
"id": "15826d80-cf0a-78c9-1acf-36fef67d89fc",
"headers": "Content-Type: application/json\n",
"headerData": [
{
"key": "Content-Type",
"value": "application/json",
"description": "",
"enabled": true
}
],
"url": "localhost:8080/v1/posts",
"queryParams": [],
"pathVariables": {},
"pathVariableData": [],
"preRequestScript": null,
"method": "POST",
"collectionId": "50f06778-83f3-3359-8bc5-cc3d0bdf582d",
"data": [],
"dataMode": "raw",
"name": "Create post",
"description": "",
"descriptionFormat": "html",
"time": 1569687903992,
"version": 2,
"responses": [],
"tests": null,
"currentHelper": "normal",
"helperAttributes": {},
"rawModeData": "{\n\t\"title\": \"post 1\",\n\t\"description\": \"post 1 description\",\n\t\"content\": \"post 1 content\"\n}"
},
{
"id": "df740598-560e-5b22-8c65-f719411d1d24",
"headers": "Content-Type: application/json\n",
"headerData": [
{
"key": "Content-Type",
"value": "application/json",
"description": "",
"enabled": true
}
],
"url": "localhost:8080/v1/posts/1/comments?page=0&size=3&sort=createdAt,desc",
"queryParams": [
{
"key": "page",
"value": "0",
"equals": true,
"description": "",
"enabled": true
},
{
"key": "size",
"value": "3",
"equals": true,
"description": "",
"enabled": true
},
{
"key": "sort",
"value": "createdAt,desc",
"equals": true,
"description": "",
"enabled": true
}
],
"pathVariables": {},
"pathVariableData": [],
"preRequestScript": null,
"method": "GET",
"collectionId": "50f06778-83f3-3359-8bc5-cc3d0bdf582d",
"data": null,
"dataMode": "params",
"name": "Retrieve all comments of a post",
"description": "",
"descriptionFormat": "html",
"time": 1569689513143,
"version": 2,
"responses": [],
"tests": null,
"currentHelper": "normal",
"helperAttributes": {}
}
]
}
7 changes: 7 additions & 0 deletions jpa-one-to-many-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>8.0.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.example.jpa;
package com.amit.jpa;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

/**
*
* @author Amit Patil
*
**/
@SpringBootApplication
@EnableJpaAuditing
public class JpaOneToManyDemoApplication {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package com.example.jpa.controller;
package com.amit.jpa.controller;

import com.amit.jpa.exception.ResourceNotFoundException;
import com.amit.jpa.model.Comment;
import com.amit.jpa.repository.CommentRepository;
import com.amit.jpa.repository.PostRepository;

import com.example.jpa.exception.ResourceNotFoundException;
import com.example.jpa.model.Comment;
import com.example.jpa.repository.CommentRepository;
import com.example.jpa.repository.PostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
*
* @author Amit Patil
*
**/
@RestController
@RequestMapping("/v1")
public class CommentController {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package com.example.jpa.controller;
package com.amit.jpa.controller;

import com.amit.jpa.exception.ResourceNotFoundException;
import com.amit.jpa.model.Post;
import com.amit.jpa.repository.PostRepository;

import com.example.jpa.exception.ResourceNotFoundException;
import com.example.jpa.model.Post;
import com.example.jpa.repository.PostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
*
* @author Amit Patil
*
**/
@RestController
@RequestMapping("/v1")
public class PostController {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package com.example.jpa.exception;
package com.amit.jpa.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
*
* @author Amit Patil
*
**/
@ResponseStatus(HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends RuntimeException {
public ResourceNotFoundException() {
/**
*
*/
private static final long serialVersionUID = -6284714764240841538L;

public ResourceNotFoundException() {
super();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
package com.example.jpa.model;
package com.amit.jpa.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
*
* @author Amit Patil
*
**/
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(
value = {"createdAt", "updatedAt"},
allowGetters = true
)
public abstract class AuditModel implements Serializable {
@Temporal(TemporalType.TIMESTAMP)
/**
*
*/
private static final long serialVersionUID = -3515832039273653354L;

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_at", nullable = false, updatable = false)
@CreatedDate
private Date createdAt;
Expand Down
Loading