Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Versioning

Svein Bruce
Svein Bruce
7,162 Points

I'm getting a 500 error: Could not commit JPA transaction. Nested exception

project is very similiar to the course one. Only difference is that i use postgresql(with no issues). I did have done a few PUT methods and they all worked except two of them. I have 6 courses objects in my database and a GET method (to http://localhost:8080/courses/) returns all six with their fields and values.

But when I try to do a PUT to either courses/2 or courses/4 with the body showed below I get the 500 Error.

PUT-request with "raw" checked, and "Content-Type" set to "application/json" body:

{
    "title": "java 2 course CHANGED",
    "url": "https://java2.com"
}

In postman I get:

"timestamp": "2019-05-09T07:25:42.534+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction",
"path": "/courses/2"

In the console I get an incredibly long error that starts with:

2019-05-09 09:25:42.520 ERROR 9072 --- [nio-8080-exec-1] o.h.i.ExceptionMapperStandardImpl        : HHH000346: Error during managed flush [null]
2019-05-09 09:25:42.528 ERROR 9072 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction] with root cause

java.lang.NullPointerException: null
    at org.hibernate.type.LongType.next(LongType.java:62) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
        THIS ERROR CONTINUES...

GET http://localhost:8080/courses Returns:

{
    "_embedded": {
        "courses": [
            {
                "title": "Da java",
                "url": "https://java.com",
                "_links": {
                    "self": {
                        "href": "http://localhost:8080/courses/1"
                    },
                    "course": {
                        "href": "http://localhost:8080/courses/1"
                    },
                    "reviews": {
                        "href": "http://localhost:8080/courses/1/reviews"
                    }
                }
            },
            {
                "title": "Da java",
                "url": "https://java.com",
                "_links": {
                    "self": {
                        "href": "http://localhost:8080/courses/2"
                    },
                    "course": {
                        "href": "http://localhost:8080/courses/2"
                    },
                    "reviews": {
                        "href": "http://localhost:8080/courses/2/reviews"
                    }
                }
            },
            {
                "title": "Spring for 47c",
                "url": "www.fgtr.no",
                "_links": {
                    "self": {
                        "href": "http://localhost:8080/courses/3"
                    },
                    "course": {
                        "href": "http://localhost:8080/courses/3"
                    },
                    "reviews": {
                        "href": "http://localhost:8080/courses/3/reviews"
                    }
                }
            },
            {
                "title": "Da java",
                "url": "https://java.com",
                "_links": {
                    "self": {
                        "href": "http://localhost:8080/courses/4"
                    },
                    "course": {
                        "href": "http://localhost:8080/courses/4"
                    },
                    "reviews": {
                        "href": "http://localhost:8080/courses/4/reviews"
                    }
                }
            },
            {
                "title": "java 5 course CHANGED",
                "url": "https://java5.com",
                "_links": {
                    "self": {
                        "href": "http://localhost:8080/courses/5"
                    },
                    "course": {
                        "href": "http://localhost:8080/courses/5"
                    },
                    "reviews": {
                        "href": "http://localhost:8080/courses/5/reviews"
                    }
                }
            },
            {
                "title": "java 6 course CHANGED",
                "url": "https://java6.com",
                "_links": {
                    "self": {
                        "href": "http://localhost:8080/courses/6"
                    },
                    "course": {
                        "href": "http://localhost:8080/courses/6"
                    },
                    "reviews": {
                        "href": "http://localhost:8080/courses/6/reviews"
                    }
                }
            }
        ]
    },
    "_links": {
        "self": {
            "href": "http://localhost:8080/courses/"
        },
        "profile": {
            "href": "http://localhost:8080/profile/courses"
        }
    }
}