Java SQLite的SpringBoot2JPA命名策略

Java SQLite的SpringBoot2JPA命名策略,java,sqlite,spring-boot,spring-data-jpa,naming-strategy,Java,Sqlite,Spring Boot,Spring Data Jpa,Naming Strategy,我想用crudepository实现springboot2应用程序。我搞不清楚我的应用程序中的命名策略是怎么回事。当我调用存储库中的方法(例如findAll())时,它会转换数据库中表的名称,导致查询崩溃。 当然,我尝试过类似问题的解决方案: Spring boot完全忽略application.properties文件中的命名策略属性(其他属性工作正常) 在spring boot 2.1.8的源代码中,我找到了策略道具的名称,并将它们复制到属性: 物理和隐式策略实现的完全限定类名可以通过分别

我想用crudepository实现springboot2应用程序。我搞不清楚我的应用程序中的命名策略是怎么回事。当我调用存储库中的方法(例如findAll())时,它会转换数据库中表的名称,导致查询崩溃。 当然,我尝试过类似问题的解决方案:

Spring boot完全忽略application.properties文件中的命名策略属性(其他属性工作正常)

在spring boot 2.1.8的源代码中,我找到了策略道具的名称,并将它们复制到属性:

物理和隐式策略实现的完全限定类名可以通过分别设置
spring.jpa.hibernate.naming.physical strategy
spring.jpa.hibernate.naming.implicit strategy
属性来配置。 或者,如果
ImplicitNamingStrategy
PhysicalNamingStrategy
bean在应用程序上下文中可用,则Hibernate将自动配置为使用它们。 但是它不起作用

多谢各位

应用程序属性

spring.application.name=file parser
driverClassName=org.sqlite.JDBC
url=jdbc:sqlite:C:\\Java\\ParseSite\\sample.db
user=admin
pass=123

#nothing works
spring.jpa.hibernate.naming.implicit-strategy=ru.laz.db.ImplicitNamingStrategyImpl
spring.jpa.hibernate.naming.physical-strategy=ru.laz.db.PhysicalNamingStrategyImpl
spring.jpa.properties.hibernate.physical_naming_strategy = ru.laz.db.PhysicalNamingStrategyImpl

spring.jpa.properties.hibernate.dialect = ru.laz.db.SQLitePrefs.SQLiteDialect
pom.xml


4.0.0
2.1.8.1发布
1.8
拉兹
解析站点
0.1.0
org.springframework.boot
spring启动程序父级
${spring.boot.version}
org.springframework.boot
SpringBootStarterWeb
${spring.boot.version}
org.asynchttpclient
异步http客户端
2.2.0
org.jsoup
jsoup
1.11.3
org.xerial
sqlite jdbc
3.16.1
org.springframework.boot
spring引导启动器数据jpa
${spring.boot.version}
com.fasterxml.jackson.core
杰克逊数据绑定
2.9.10
org.springframework.boot
springbootmaven插件
NewsBlockRepo.java

@存储库
公共接口NewsBlockRepo扩展了Crudepository{
//只有这个方法可行
@修改
@交易的
@查询(value=“插入或替换到新闻块(日期、标题、url、正文、已发送)值(:日期、:标题、:url、:正文、:已发送)”,nativeQuery=true)
void insertOrIgnore(@Param(“date”)字符串日期、@Param(“title”)字符串标题、@Param(“url”)字符串url、@Param(“body”)字符串正文、@Param(“sent”)int sent);
}
NewsBlock.java

包ru.laz.db;
导入javax.persistence.*;
@实体
@表(name=“新闻块”)
公共类新闻块{
@身份证
@列(name=“id”)
@GeneratedValue(策略=GenerationType.IDENTITY)
私有int-id;
@列(name=“date”)
私有字符串date=“;//用于sqlite中的唯一常量
@列(name=“title”)
私有字符串title=“”;
@列(name=“url”)
私有字符串url=“”;
@列(name=“body”)
私有字符串体=”;
@列(name=“sent”)
发送的私有int=0;
公共长getId(){
返回id;
}
公共无效集合id(内部id){
this.id=id;
}
公共字符串getDate(){
返回日期;
}
公共无效设置日期(字符串日期){
this.date=日期;
}
公共字符串getTitle(){
返回标题;
}
公共无效集合标题(字符串标题){
this.title=标题;
}
公共字符串getBody(){
返回体;
}
公共体(字符串体){
这个身体=身体;
}
公共字符串getUrl(){
返回url;
}
公共void setUrl(字符串url){
this.url=url;
}
public int getSent(){
返回发送;
}
公共无效设置(int已发送){
this.sent=sent;
}
@凌驾
公共布尔等于(对象o){
如果(o==this)返回true;
如果(!(o新闻块实例)){
返回false;
}
新闻块nb=(新闻块)o;
返回this.url.equals(nb.getUrl())&&this.title.equals(nb.getTitle())&&this.body.equals(nb.getBody());
}
@凌驾
公共字符串toString(){
返回“日期:”+日期+”标题:“+标题+”url:“+url+”文本:”+正文;
}
}
我的物理竞赛策略

公共类PhysicalNamingStrategyImpl扩展PhysicalNamingStrategyTempl实现可序列化{
public static final PhysicalNamingStrategyImpl实例=新PhysicalNamingStrategyImpl();
@凌驾
公共标识符TopPhysicalTableName(标识符名称,JdbcEnvironment上下文){
String nameModified=name.getText();
//对名称进行任何修改
返回新标识符(nameModified,name.isQuoted());
}
}
甚至是隐含的策略

公共类ImplicitNamingStrategyImpl扩展了implicitnamingstrategyjpacomplianimpl{
@凌驾
受保护的标识符到标识符(字符串stringForm、MetadataBuildingContext buildingContext){
返回super.toIdentifier(stringForm、buildingContext);
}
}
最终控制器从存储库调用方法

@RequestMapping(“/getUnsent”)
公共字符串getUnsent()引发异常{
返回objectMapper.writeValueAsString(newsBlockRepo.findAll());
}
错误:

org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such column: newsblock0_.id)

错误是
没有这样的列:newsblock0.id
。显然,它在
news\u block
block表中指出,没有
id
,这意味着,spring boot在声明实体类后,就将其视为
id
。实体类或多或少等于您的表

它要求您声明的所有变量都必须在表中,但有时您声明的变量为n
org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such column: newsblock0_.id)