In my application there is an entity:
@Entity
@Table(schema = "hr", name = "personal_data")
public class PersonalData {
}
and connection string defined in Spring's application.properties:
spring.datasource.url=jdbc:mysql://localhost/mobile?UseUnicode=true&characterEncoding=utf8
If I invoke the following code:
TypedQuery<E> typedQuery = em.createQuery("from PersonalData pd where pd.employeeId = ?1", PersonalData.class);
typedQuery.setParameter(1, 123);
return typedQuery.getSingleResult();
it will result in this SQL:
select * from personal_data personalda0_ where personalda0_.employee_id=?
Which will fail with the exception
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mobile.personal_data' doesn't exist
because the table personal_data
is defined in the hr
database and there is no such table in mobile
.
This was working fine(i.e. 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. Is there any way to achieve the old behaviour in Hibernate 5.x?