大佬教程收集整理的这篇文章主要介绍了在 Spring Data JPA 中执行 INSERT 时出错,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我得到一个
org.h2.jdbc.JdbcsqlSyntaxErrorException: column "PRICEAFTERdisCOUNT" not found; sql statement:
@H_404_6@
这是我的物品类
package com.example.demo.model.persistence;
import java.math.bigdecimal;
import javax.persistence.column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.ID;
import javax.persistence.Joincolumn;
import javax.persistence.ManyToOne;
import javax.persistence.table;
import com.fasterxml.jackson.Annotation.JsonProperty;
import lombok.Data;
@Entity
@Data
@table(name = "item")
public class Item {
@ID
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonProperty
private Long ID;
@column(nullable = falsE)
@JsonProperty
private String name;
@column(nullable = falsE)
@JsonProperty
private Bigdecimal price;
@column(nullable = falsE)
@JsonProperty
private Bigdecimal priceAfterdiscount;
@column(nullable = falsE)
@JsonProperty
private String description;
@OverrIDe
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((ID == null) ? 0 : ID.hashCode());
return result;
}
@OverrIDe
public Boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Item other = (Item) obj;
if (ID == null) {
if (other.ID != null)
return false;
} else if (!ID.equals(other.ID))
return false;
return true;
}
}
这是我的 data.sql
文件
insert into item (name,price,priceAfterdiscount,description) values ('Travel Card Holder',9.25,'A holder for your travel card');
insert into item (name,description) values ('Personalised cufflinks',45.00,'Cufflings with your initials');
insert into item (name,description) values ('KIDs T-shirt',19.95,'A T-shirt with dinosaurs')
据我所知,我已将 priceAfterdiscount
添加到我的插入语句中,因此我不会
了解错误来自哪里,或者首先为什么会发生。请帮忙!
我在 Item 类中添加了 priceAfterdiscount 字段。并以与其余字段相同的方式进行注释。另外,语法对我来说是正确的
异常意味着您的数据库表 item
不包含名为 PRICEAFTERDISCOUNT
的列。检查数据库列名并将其添加到字段注释参数上@column(name="database_column_name",nullable = falsE)
。
data.sql
语句也必须包含正确的列名。
以上是大佬教程为你收集整理的在 Spring Data JPA 中执行 INSERT 时出错全部内容,希望文章能够帮你解决在 Spring Data JPA 中执行 INSERT 时出错所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。