Skip to content

hibernate error, can't find solution #944

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

BelitskyiAlexandr
Copy link

Hibernate doesn't create tables automatically. If create tables manually, it works and fails at next table 'actors'.

Here is the stack of the problem:

INFO: HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
Hibernate: 
    insert 
    into
        countries
        (name) 
    values
        (?)
июл. 20, 2024 4:27:02 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1146, SQLState: 42S02
июл. 20, 2024 4:27:02 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Table 'movies.countries' doesn't exist
Exception in thread "main" mate.academy.hibernate.relations.exception.DataProcessingException: Cannot add the country: Country{id=null, name='USA'}
	at mate.academy.hibernate.relations.dao.impl.AbstractDao.add(AbstractDao.java:32)
	at mate.academy.hibernate.relations.dao.impl.CountryDaoImpl.add(CountryDaoImpl.java:17)
	at mate.academy.hibernate.relations.service.impl.CountryServiceImpl.add(CountryServiceImpl.java:16)
	at mate.academy.hibernate.relations.Main.main(Main.java:23)

Process finished with exit code 1

It would be great if you can help me, because I did not find the solution on StackOverflow. Theese articles did not helped me:
https://coderanch.com/t/636771/frameworks/Table-mydb-temp-doesn-exist
spring-projects/spring-data-commons#2761
https://discourse.hibernate.org/t/hibernate-couldnt-find-table/1888/4
https://stackoverflow.com/questions/438146/what-are-the-possible-values-of-the-hibernate-hbm2ddl-auto-configuration-and-wha
https://stackoverflow.com/questions/4490981/hibernate-table-does-not-exist-error

@BelitskyiAlexandr
Copy link
Author

BelitskyiAlexandr commented Jul 20, 2024

It is very strange. The tests pass, but hibernate doesn't create the table when I run Main. Table countries created manually by cmd line in MySQL.

Stack:

WARN: HHH90000026: MySQL8Dialect has been deprecated; use org.hibernate.dialect.MySQLDialect instead
июл. 20, 2024 5:14:06 PM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
Hibernate: 
    insert 
    into
        countries
        (name) 
    values
        (?)
Hibernate: 
    insert 
    into
        actors
        (country_id, name) 
    values
        (?, ?)
июл. 20, 2024 5:14:06 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1146, SQLState: 42S02
июл. 20, 2024 5:14:06 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Table 'movies.actors' doesn't exist
Exception in thread "main" mate.academy.hibernate.relations.exception.DataProcessingException: Cannot add the actor: Actor{id=null, name='Vin Diesel', country='Country{id=1, name='USA'}'}
	at mate.academy.hibernate.relations.dao.impl.ActorDaoImpl.add(ActorDaoImpl.java:29)
	at mate.academy.hibernate.relations.service.impl.ActorServiceImpl.add(ActorServiceImpl.java:19)
	at mate.academy.hibernate.relations.Main.main(Main.java:28)

Copy link

@Elena-Bruyako Elena-Bruyako left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments
If you have questions, please ask in chat

<property name="connection.password">rootroot</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.hbm2dd1.auto">update</property>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<property name="hibernate.hbm2dd1.auto">update</property>
<property name="hibernate.hbm2dd1.auto">create-drop</property>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking for a way to solve the problem described above, this was one of the types of its solution.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use create-drop, it's not related to your exception

@BelitskyiAlexandr
Copy link
Author

What is the difference where to ask here or in the chat, if I described the problem in detail here? Anyway, you are initially in the context of the task

@Elena-Bruyako
Copy link

It is very strange. The tests pass, but hibernate doesn't create the table when I run Main. Table countries created manually by cmd line in MySQL.

Stack:

WARN: HHH90000026: MySQL8Dialect has been deprecated; use org.hibernate.dialect.MySQLDialect instead
июл. 20, 2024 5:14:06 PM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
Hibernate: 
    insert 
    into
        countries
        (name) 
    values
        (?)
Hibernate: 
    insert 
    into
        actors
        (country_id, name) 
    values
        (?, ?)
июл. 20, 2024 5:14:06 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1146, SQLState: 42S02
июл. 20, 2024 5:14:06 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Table 'movies.actors' doesn't exist
Exception in thread "main" mate.academy.hibernate.relations.exception.DataProcessingException: Cannot add the actor: Actor{id=null, name='Vin Diesel', country='Country{id=1, name='USA'}'}
	at mate.academy.hibernate.relations.dao.impl.ActorDaoImpl.add(ActorDaoImpl.java:29)
	at mate.academy.hibernate.relations.service.impl.ActorServiceImpl.add(ActorServiceImpl.java:19)
	at mate.academy.hibernate.relations.Main.main(Main.java:28)

You named your database (movies) the same as one of the table (movies). That's why you've got an exception.
Rename to movie_db for example

<property name="connection.password">rootroot</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.hbm2dd1.auto">update</property>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use create-drop, it's not related to your exception

@BelitskyiAlexandr
Copy link
Author

It is very strange. The tests pass, but hibernate doesn't create the table when I run Main. Table countries created manually by cmd line in MySQL.
Stack:

WARN: HHH90000026: MySQL8Dialect has been deprecated; use org.hibernate.dialect.MySQLDialect instead
июл. 20, 2024 5:14:06 PM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
Hibernate: 
    insert 
    into
        countries
        (name) 
    values
        (?)
Hibernate: 
    insert 
    into
        actors
        (country_id, name) 
    values
        (?, ?)
июл. 20, 2024 5:14:06 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1146, SQLState: 42S02
июл. 20, 2024 5:14:06 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Table 'movies.actors' doesn't exist
Exception in thread "main" mate.academy.hibernate.relations.exception.DataProcessingException: Cannot add the actor: Actor{id=null, name='Vin Diesel', country='Country{id=1, name='USA'}'}
	at mate.academy.hibernate.relations.dao.impl.ActorDaoImpl.add(ActorDaoImpl.java:29)
	at mate.academy.hibernate.relations.service.impl.ActorServiceImpl.add(ActorServiceImpl.java:19)
	at mate.academy.hibernate.relations.Main.main(Main.java:28)

You named your database (movies) the same as one of the table (movies). That's why you've got an exception. Rename to movie_db for example

I've already tried something like that, it did not helped:

июл. 21, 2024 10:40:59 PM org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl logSelectedDialect
WARN: HHH90000026: MySQL8Dialect has been deprecated; use org.hibernate.dialect.MySQLDialect instead
июл. 21, 2024 10:41:01 PM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
Hibernate: 
    insert 
    into
        countries
        (name) 
    values
        (?)
июл. 21, 2024 10:41:01 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1146, SQLState: 42S02
июл. 21, 2024 10:41:01 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Table 'movies_db.countries' doesn't exist
Exception in thread "main" mate.academy.hibernate.relations.exception.DataProcessingException: Cannot add the country: Country{id=null, name='USA'}
	at mate.academy.hibernate.relations.dao.impl.CountryDaoImpl.add(CountryDaoImpl.java:30)
	at mate.academy.hibernate.relations.service.impl.CountryServiceImpl.add(CountryServiceImpl.java:17)
	at mate.academy.hibernate.relations.Main.main(Main.java:26)

Process finished with exit code 1

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

Successfully merging this pull request may close these issues.

3 participants