可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I tried to upgrade hibernate from 4 to 5 in my project with spring 4.2
version. After this upgrade, I found the following error in my stack trace when I called a method for updating.
10:53:32,185 ERROR TableStructure:149 - could not read a hi value com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.hibernate_sequence' doesn't exist
I changed the auto incremented Id with annotation
@GeneratedValue(strategy=GenerationType.AUTO)
still the error remains.
回答1:
You can also put :
@GeneratedValue(strategy = GenerationType.IDENTITY)
And let the DateBase manage the incrementation of the primary key:
AUTO_INCREMENT PRIMARY KEY
回答2:
You need to set false
.. see link and link.
回答3:
I was getting the same error-"com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mylocaldb.hibernate_sequence' doesn't exist".
using spring mvc 4.3.7 and hibernate version 5.2.9, application is made using spring java based configuration, now i have to add the "hibernate.id.new_generator_mappings" property mentioned by @Eva Mariam in my code like this:
@Autowired @Bean(name = "sessionFactory") public SessionFactory getSessionFactory(DataSource dataSource) { LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource); sessionBuilder.addProperties(getHibernateProperties()); sessionBuilder.addAnnotatedClasses(User.class); return sessionBuilder.buildSessionFactory(); } private Properties getHibernateProperties() { Properties properties = new Properties(); properties.put("hibernate.show_sql", "true"); properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); properties.put("hibernate.id.new_generator_mappings","false"); return properties; }
and it worked like charm.
回答4:
This is the reason behind this error:
It will look for how the database that you are using generates ids. For MySql or HSQSL, there are increment fields that automatically increment. In Postgres or Oracle, they use sequence tables. Since you didn't specify a sequence table name, it will look for a sequence table named hibernate_sequence and use it for default. So you probably don't have such a sequence table in your database and now you get that error.
回答5:
FYI
If you are using hbm files to define the O/R mapping.
Notice that:
In Hibernate 5, the param name for the sequence name has been changed.
The following setting worked fine in Hibernate 4:
xxxxxx_seq
But in Hibernate 5, the same mapping setting file will cause a "hibernate_sequence doesn't exist" error.
To fix this error, the param name must change to:
xxxxxx_seq
This problem wasted me 2, 3 hours.
And somehow, it looks like there are no document about it.
I have to read the source code of org.hibernate.id.enhanced.SequenceStyleGenerator to figure it out
回答6:
This might be caused by HHH-10876 which got fixed so make sure you update to:
- Hibernate ORM 5.2.1,
- Hibernate ORM 5.1.1,
- Hibernate ORM 5.0.11