我有一個第三方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