I cloned this repo then I have this error when:
List All tutorials:
curl --location --request GET 'localhost:8080/api/tutorials' \
--header 'Cookie: X-TIRTA-SESSION=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwaG9uZSI6IjYyODIzMjA0MDQwOTciLCJpZCI6IjFmYzVjNTU5LTFkZGItNDFlOS04NjAzLWJkOGVlYTEyOTY0ZCIsInVzZXJJZCI6IjRjMWQ1MDJmLTRiYWQtNGQ5MS1iMDdlLTA5Y2IxMDgyMjRkZCJ9.jF5iav9H9mWYxXIrEI_NLpAAHeJBjqd4gAU5dbmk-_c'
Error
[
{
"id": 1,
"title": "JPA/Hibernate Many to Many",
"description": "Tutorial #1",
"published": true,
"tags"
}
]{
"statusCode": 500,
"timestamp": "2022-07-12T11:03:09.315+00:00",
"message": "Could not write JSON: failed to lazily initialize a collection of role: com.bezkoder.spring.hibernate.manytomany.model.Tutorial.tags, could not initialize proxy - no Session; nested exception is com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: com.bezkoder.spring.hibernate.manytomany.model.Tutorial.tags, could not initialize proxy - no Session (through reference chain: java.util.ArrayList[0]->com.bezkoder.spring.hibernate.manytomany.model.Tutorial[\"tags\"])",
"description": "uri=/api/tutorials"
}
Then I tried to add tag into tutorial:
curl --location --request POST 'localhost:8080/api/tutorials/1/tags' \
--header 'Content-Type: application/json' \
--header 'Cookie: X-TIRTA-SESSION=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwaG9uZSI6IjYyODIzMjA0MDQwOTciLCJpZCI6IjFmYzVjNTU5LTFkZGItNDFlOS04NjAzLWJkOGVlYTEyOTY0ZCIsInVzZXJJZCI6IjRjMWQ1MDJmLTRiYWQtNGQ5MS1iMDdlLTA5Y2IxMDgyMjRkZCJ9.jF5iav9H9mWYxXIrEI_NLpAAHeJBjqd4gAU5dbmk-_c' \
--data-raw '{
"name": "Spring"
}'
Also got error:
{
"statusCode": 500,
"timestamp": "2022-07-12T11:03:23.072+00:00",
"message": "failed to lazily initialize a collection of role: com.bezkoder.spring.hibernate.manytomany.model.Tutorial.tags, could not initialize proxy - no Session",
"description": "uri=/api/tutorials/1/tags"
}