简体   繁体   中英

Hibernate tries to insert data to a table that does not exist

I have a database about movies and actors. I want to do is : I want to fetch actor data (like name, surname, country, date of birth) from the corresponding arrayLists and insert that data into my actor table. And i want to do the same thing to my movie table. Here is a part of my code :

Then i am getting these errors :

  • Exception in thread "main" javax.persistence.RollbackException: Error while committing the transaction

    -Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement

    -Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement

    -Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'movies and tv series.actor_country' doesn't exist

The thing that i don't understand is why hibernate tries to insert data to a table that does not exist. I don't want a actor_country table. Can somebody help me please ?

I have created a no-argument constructor and initialize the arrayLists with some data.

Unfortunately, with your current design, you're stuck with an actor_country table. Defining a property as @ElementCollection of type List is going to create a child table. How else would you store multiple countries in a relational database? You can control the name of the table by using the @CollectionTable in conjunction with the @ElementCollection .

If you don't want to store multiple countries, you can switch it to @Basic with a type of String .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM