0

I'm creating a POC for using Spring boot with my next project. Now I created a rest service that wil query all the data from a MS sql server database.

The entity that I want to query looks like:

@Entity @Table(name = "Item", schema = "materialManagement", uniqueConstraints = @UniqueConstraint(columnNames = { "companyID", "number" })) public class Item implements java.io.Serializable { //all variabels are placed here } 

Now when I create a repository for the Item class:

public interface NoteRepository extends JpaRepository<Item, Long> { } 

In my controller I autowire the repo and query the repo with findAll():

@RestController @RequestMapping("/api") public class NoteController { @Autowired NoteRepository noteRepository; @GetMapping("/notes") public List<Item> getAllNotes() { return noteRepository.findAll(); } } 

Now when I send a request to the controller I got following error:

com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'material_management.item'.

In the database there is indeed no material_management schema only materialManagement. But from where does that generated schema come from?

My application.properties looks like:

> spring.datasource.url = > jdbc:sqlserver://localhost:1433;databaseName=CR_ApplicationSuite;integratedSecurity=true; > > spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver > ## Hibernate Properties > > # The SQL dialect makes Hibernate generate better SQL for the chosen database spring.jpa.properties.hibernate.dialect = > org.hibernate.dialect.SQLServer2008Dialect 
2

2 Answers 2

5

I added following lines to the application.properties:

spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 
Sign up to request clarification or add additional context in comments.

Comments

1

The Hibernate naming strategy replaces camel case with _

In your case:

@Table(name = "Item", schema = "materialManagement", ... 

Becomes

material_management 

Solution

Either remove the camel case with all lower case or if it must be camel case you must change the Hibernate naming strategy.

Application properties:

spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.