Skip to content

Cosium/spring-data-jpa-entity-graph-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Data JPA Entity Graph Sample

Sample application demonstrating https://github.com/Cosium/spring-data-jpa-entity-graph setup and usage.

How to play with it

Run com.cosium.spring_data_jpa_entity_graph_sample.App, then try to invoke the exposed endpoints. Keep an eye on the application console to see the SQL queries generated by each request.

List products without brands

GET http://localhost:8080/products/

select product0_.id       as id1_1_,
       product0_.brand_id as brand_id3_1_,
       product0_.name     as name2_1_
from product product0_
[
  {
    "id": 1,
    "name": "Model S",
    "brandName": "Not loaded"
  },
  {
    "id": 2,
    "name": "Model Y",
    "brandName": "Not loaded"
  },
  {
    "id": 3,
    "name": "Model X",
    "brandName": "Not loaded"
  },
  {
    "id": 4,
    "name": "A7",
    "brandName": "Not loaded"
  },
  {
    "id": 5,
    "name": "TT",
    "brandName": "Not loaded"
  },
  {
    "id": 6,
    "name": "R8",
    "brandName": "Not loaded"
  }
]

List products with brands

GET http://localhost:8080/products?with_brand=true

select product0_.id       as id1_1_0_,
       brand1_.id         as id1_0_1_,
       product0_.brand_id as brand_id3_1_0_,
       product0_.name     as name2_1_0_,
       brand1_.name       as name2_0_1_
from product product0_
         left outer join
     brand brand1_ on product0_.brand_id = brand1_.id
[
  {
    "id": 1,
    "name": "Model S",
    "brandName": "Tesla"
  },
  {
    "id": 2,
    "name": "Model Y",
    "brandName": "Tesla"
  },
  {
    "id": 3,
    "name": "Model X",
    "brandName": "Tesla"
  },
  {
    "id": 4,
    "name": "A7",
    "brandName": "Audi"
  },
  {
    "id": 5,
    "name": "TT",
    "brandName": "Audi"
  },
  {
    "id": 6,
    "name": "R8",
    "brandName": "Audi"
  }
]

Get product by id

GET http://localhost:8080/products/1

select product0_.id       as id1_1_0_,
       product0_.brand_id as brand_id3_1_0_,
       product0_.name     as name2_1_0_,
       brand1_.id         as id1_0_1_,
       brand1_.name       as name2_0_1_
from product product0_
         inner join
     brand brand1_ on product0_.brand_id = brand1_.id
where product0_.id = ?
{
  "id": 1,
  "name": "Model S",
  "brandName": "Tesla"
}

Releases

No releases published

Packages

No packages published

Languages