![](/img/trans.png)
[英]Hibernate ignores @GeneratedValue when creating schema on Postgresql
[英]Hibernate 5 ignores @Table schema param
在我的应用程序中有一个实体:
@Entity
@Table(schema = "hr", name = "personal_data")
public class PersonalData {
}
以及在 Spring 的 application.properties 中定义的连接字符串:
spring.datasource.url=jdbc:mysql://localhost/mobile?UseUnicode=true&characterEncoding=utf8
如果我调用以下代码:
TypedQuery<E> typedQuery = em.createQuery("from PersonalData pd where pd.employeeId = ?1", PersonalData.class);
typedQuery.setParameter(1, 123);
return typedQuery.getSingleResult();
这将导致这个 SQL:
select * from personal_data personalda0_ where personalda0_.employee_id=?
哪个会失败,但有例外
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mobile.personal_data' doesn't exist
因为表personal_data
是在hr
数据库中定义的,而mobile
中没有这样的表。
This was working fine(ie table name in SQL was prefixed with database name) in Hibernate 4.3.13 and stopped when the application was migrated to Spring Boot 2.0 which uses Hibernate 5.2.14. 有什么方法可以实现 Hibernate 5.x 中的旧行为?
我可以说Hibernate 5和MySQL之间存在误解 ,这里的长篇故事Hibernate 5.0.6忽略了MySQL中的模式
建议的一个解决方案是在目录的位置使用模式的名称,而不是:
@Table(schema = "hr", name = "personal_data")
^^^^^^
您可以使用 :
@Table(catalog = "hr", name = "personal_data")
^^^^^^^
另外看看这个:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.