【发布时间】:2018-07-07 21:41:09
【问题描述】:
我正在创建一个 POC,以便在我的下一个项目中使用 Spring Boot。 现在我创建了一个休息服务,它将从 MS sql 服务器数据库中查询所有数据。
我要查询的实体如下:
@Entity
@Table(name = "Item", schema = "materialManagement", uniqueConstraints = @UniqueConstraint(columnNames = {
"companyID", "number" }))
public class Item implements java.io.Serializable {
//all variabels are placed here
}
现在,当我为 Item 类创建存储库时:
public interface NoteRepository extends JpaRepository<Item, Long> {
}
在我的控制器中,我自动装配 repo 并使用 findAll() 查询 repo:
@RestController
@RequestMapping("/api")
public class NoteController {
@Autowired
NoteRepository noteRepository;
@GetMapping("/notes")
public List<Item> getAllNotes() {
return noteRepository.findAll();
}
}
现在,当我向控制器发送请求时,出现以下错误:
com.microsoft.sqlserver.jdbc.SQLServerException:对象名称无效 'material_management.item'。
在数据库中确实没有 material_management 模式,只有 materialManagement。但是生成的模式是从哪里来的呢?
我的 application.properties 看起来像:
> 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
【问题讨论】:
-
你能发布你的 Hibernate 属性
标签: hibernate spring-boot spring-data-jpa