我有一个第三方jar包含所有的实体和映射。我目前在经典的Spring-MVC应用程序中成功地使用了这个jar,但现在我正试图在Spring-Boot应用程序中使用它。 (1.5.7.RELEASE)春季引导 - 休眠 - 表不存在
我为我的Applicaion.java:
@SpringBootApplication
@EntityScan(basePackages = "com.third.party.entity.package")
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
由于它是一个第三方的,我必须有会话扫描以及所以我有这个在我的@配置类:
@Bean
public LocalSessionFactoryBean sessionFactory(EntityManagerFactory emf) throws ClassNotFoundException {
LocalSessionFactoryBean fact = new LocalSessionFactoryBean();
fact.setAnnotatedPackages("com.third.party.entity.package");
fact.setPackagesToScan("com.third.party.entity.package");
fact.setDataSource(dataSource);
return fact;
}
,这在我的application.properties:
spring.datasource.url=jdbc:mysql://dbserver:3306/mydb?useSSL=false
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=20
spring.datasource.tomcat.min-idle=15
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.id.new_generator_mappings = false
spring.jpa.properties.hibernate.format_sql = true
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
我收到此错误:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mydb.user' doesn't exist
现在,表名是“用户”,这样的排序是有道理的。但是,我正在使用此jar来处理另一个应用程序,所以关于此主题的其他100个答案都不适用。
它必须是一个配置问题?对?
UPDATE 我试图@sam回答以下无济于事,但我能看一下这个第三方jar文件的源代码,它看起来像这样:
@Entity
@Table(name = "User")
public class User {
etc...
}
所以注释中的表名是正确的。我如何让Spring使用它?我寻找一个默认的命名策略和东西...任何建议?
我无法设置DDL-AUTO更新,因为我无法更改数据库。排除HibernateJpaAutoConfiguration只是给了我一个未找到的类型为'javax.persistence.EntityManagerFactory'的bean的bean' – mmaceachran
@mmaceachran你检查@EntityScan(basePackages =“com.third.party.entity.package”)是否正确! – 2017-10-08 00:41:02
是的,那是正确的包装。例如,我刚刚重命名了它。我编辑了我的问题,以便显示User类。 – mmaceachran