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

Spring In Action chapter 3 - issues after migration to JPA #127

Open
MuhammadFaiq123 opened this issue May 20, 2023 · 2 comments
Open

Spring In Action chapter 3 - issues after migration to JPA #127

MuhammadFaiq123 opened this issue May 20, 2023 · 2 comments

Comments

@MuhammadFaiq123
Copy link

I am creating this thread to share some of the problems that I faced at the end of the chapter 3 after migration to JPA. I believe the steps provided in the book are not enough and I had to change some of the things to make the things work.

Feel free to add your experience in this.

@MuhammadFaiq123
Copy link
Author

Issue:
org.h2.jdbc.JdbcSQLSyntaxErrorException: Sequence "HIBERNATE_SEQUENCE" not found; SQL statement:
call next value for hibernate_sequence [90036-214]

Solution:

The error message suggests that the sequence "HIBERNATE_SEQUENCE" is not found in the H2 database. This sequence is commonly used by Hibernate to generate unique IDs for entities.

So, please add below line in the "schema.sql" file:
CREATE SEQUENCE HIBERNATE_SEQUENCE START WITH 1 INCREMENT BY 1;

@MuhammadFaiq123
Copy link
Author

MuhammadFaiq123 commented May 20, 2023

Issue:
insert into Taco_Ingredient (Taco_id, ingredients_id) values (?, ?) [42122-214]
2023-05-05 00:58:39.753 ERROR 35536 --- [nio-8080-exec-6] 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.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [insert into Taco_Ingredient (Taco_id, ingredients_id) values (?, ?)]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement] with root cause

org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "TACO_ID" not found; SQL statement:
insert into Taco_Ingredient (Taco_id, ingredients_id) values (?, ?) [42122-214]

Solution:

Change the schema and add Taco_id and ingredients_id in respective tables because when you added @manytomany annotation in the beans of Taco and Ingredient then the JPA would by default first find the table Taco_Ingredient by combining these two and then find its primary keys by following [fieldName in beans class on which ManytoMany annotaiton is added] + "_" + "id"

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