Reputation: 5648
I am trying to use spring-data-rest with MySql with hibernate as the JPA provider.
I want the table names used in the query to match the simple name of the class; Nothing more. How do I achieve that?
I have tried all of the naming strategies and it seems to have no effect. In addition, I have added
@Table("Foo")
And it gets lowercased as well
Here is the error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'TEST.worker' doesn't exist
Here is the entity:
@Entity
public class Worker {
private Long id;
private String givenName;
private String familyName;
private LocalDate dob;
private String nationalId;
private byte[] photo;
public Worker() {
this.id = Math.abs(new Random().nextLong());
}
@Id
@Column(name = "ID")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Basic
@Column(name = "GivenName")
public String getGivenName() {
return givenName;
}
public void setGivenName(String givenName) {
this.givenName = givenName;
}
@Basic
@Column(name = "FamilyName")
public String getFamilyName() {
return familyName;
}
public void setFamilyName(String familyName) {
this.familyName = familyName;
}
@Basic
@Column(name = "DOB")
public LocalDate getDob() {
return dob;
}
public void setDob(LocalDate dob) {
this.dob = dob;
}
@Basic
@Column(name = "NationalID")
public String getNationalId() {
return nationalId;
}
public void setNationalId(String nationalId) {
this.nationalId = nationalId;
}
@Basic
@Column(name = "photo")
public byte[] getPhoto() {
return photo;
}
public void setPhoto(byte[] photo) {
this.photo = photo;
}
}
My relevant config:
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=true
spring.jpa.generate-ddl = false
spring.jpa.hibernate.ddl-auto = none
spring.jpa.hibernate.naming-strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy
Transitive dependencies from spring data:
[INFO] | +- org.hibernate:hibernate-entitymanager:jar:4.3.11.Final:compile
[INFO] | | +- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
[INFO] | | +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] | | \- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
This link doesn't apply;
Upvotes: 2
Views: 6320
Reputation: 4392
Since you are using SpringNamingStrategy
it uses the same values as the ImprovedNamingStrategy from Hibernate (verify it here).
If you check the link for ImprovedNamingStrategy
you will see that the default behavior for tableName
is to lowercase any mixed case names, which seems to be your case.
Upvotes: 2