Im building a Spring Boot application which is auto configuring my JPA datasource based on the below properties.
spring.datasource.url=jdbc:jtds:sqlserver://localhost;DatabaseName=testDB;useCursors=true
spring.datasource.username=testDBUser
spring.datasource.password=test123
spring.datasource.driver-class-name=net.sourceforge.jtds.jdbc.Driver
spring.datasource.maxActive=100
spring.datasource.minIdle=5
spring.datasource.removeAbandoned=true
spring.datasource.removeAbandonedTimeout=300
spring.datasource.defaultTransactionIsolation=REPEATABLE_READ
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.use_query_cache=true
Now, I have a table as below
TableA{
String id;
String prop1;
String prop2;
String prop3;
}
The test case that fails is below. As you can see below I'm just trying to compare the result from EntityManager vs Spring Data Repository.
The test fails because the "id" value returned from EntityManager is "D97" (upper case) and the value returned from Spring Data repository is "d97". The actual value is "d97".
@Test
public void testIfSpringRepositoryWorks() {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
List<TableAEntity> result = entityManager.createQuery("FROM TableAEntity WHERE id='d97'" , TableAEntity.class).getResultList();
if(result==null) {
Assert.fail("Empty Result from EntityManager for id: d97 ");
} else {
TableAEntity fromEntityManager = result.get(0);
TableAEntity fromSpringJPA = tableARepository.findOne("d97");
if(!fromEntityManager.equals(fromSpringJPA)) {
Assert.fail("TableAEntity is not same");
}
}
entityManager.getTransaction().commit();
entityManager.close();
}
I'm not sure on why EntityManager is converting my id field to upper case. Please help in finding out the root cause.
Thanks!