Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Lazy Loading #1

Open
hendisantika opened this issue Jul 12, 2022 · 0 comments
Open

Error Lazy Loading #1

hendisantika opened this issue Jul 12, 2022 · 0 comments

Comments

@hendisantika
Copy link

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"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant