com.transportation.model.Circumstance column: truck_model_numbe (should be mapped with insert="false

本文介绍在使用SpringBoot与SpringDataJPA构建项目时,遇到的重复列映射错误及其解决方法。错误出现在尝试初始化数据库时,由于实体类中@Column注解的name属性重复导致。通过修改实体类中的字段名,成功解决了问题并创建了数据库表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天刚用springboot +spring data jpa 来构建项目,在搭建javaBean来自动初始化数据库的时候,出现了这个错误:

 Repeated column in mapping for entity: com.transportation.model.Circumstance column: truck_model_numbe (should be mapped with insert="false" update="false")
 

附上源码,如下:


@SuppressWarnings("serial")
@Entity
@Table(name = "Circumstance")
public class Circumstance  implements Serializable{
    @EmbeddedId
    private TruckAndCircumstance id;
    @Column(name="circumstance_range")
    private String circumstance_range; //情况区间
    @Column(name="circumstance_range")
    private String circumstance_key;//情况值
    
    public String getCircumstance_range() {
        return circumstance_range;
    }
    public TruckAndCircumstance getId() {
        return id;
    }
    public void setId(TruckAndCircumstance id) {
        this.id = id;
    }
    public void setCircumstance_range(String circumstance_range) {
        this.circumstance_range = circumstance_range;
    }
    public String getCircumstance_key() {
        return circumstance_key;
    }
    public void setCircumstance_key(String circumstance_key) {
        this.circumstance_key = circumstance_key;
    }
    @Override
    public String toString() {
        return "Circumstance [id=" + id + ", circumstance_range=" + circumstance_range + ", circumstance_key="
                + circumstance_key + "]";
    }
    
}
因为创建了很多个实体,所有后面的都是复制过模板去的,所以也就是这样才出的错(别喷,怪自己懒),来,看这里:

这里的@Column中的name值相同,也就是说在数据库中,不能存在相同的字段,所以才会出错,然后将上面的代码改一下,得如下:

运行:

到这里,这个实体类就被成功在数据库中创建啦。

本文原创,转载请附上博主小名,谢谢~

>>> columns_to_fill = ['组合名称','组合ID','投顾名称','投顾ID','wind证券代码','证券名称','持仓时间','持仓数量', '持仓买入成本'] >>> grouped = df_position_temp.groupby(['组合名称', 'wind证券代码']) >>> total= len(grouped) >>> index = 0 >>> time1 = dt.datetime.now() #统计开始时间 >>> w.start(waitTime=480) # 启动wind,设置超时时间 Welcome to use Wind Quant API for Python (WindPy)! COPYRIGHT (C) 2024 WIND INFORMATION CO., LTD. ALL RIGHTS RESERVED. IN NO CIRCUMSTANCE SHALL WIND BE RESPONSIBLE FOR ANY DAMAGES OR LOSSES CAUSED BY USING WIND QUANT API FOR Python. .ErrorCode=0 .Data=[OK!] >>> for group_name, group in grouped: ... # 对每个组合中的每个证券,查找wind收盘价数据 ... code_w = group.at[0, 'wind证券代码'] # 取第一个 ... print(code_w) ... start = group.index.min().strftime('%Y-%m-%d') ... print(start) ... end = group.index.max().strftime('%Y-%m-%d') ... print(end) ... Wind_D = w.wsd(code_w, "close", start, end, "Fill=Previous") # 获取收盘价, 无交易的日期用前一个交易日的收盘价填充 ... Wind_df = pd.DataFrame(Wind_D.Data,index=Wind_D.Codes,columns=Wind_D.Times) # 转换为DataFrame格式 ... Wind_df = Wind_df.T # 转置 ... print(Wind_df) ... # 转置后格式 000538.SZ 002372.SZ ... # 2024-09-18 50.46 10.59 ... # 2024-09-19 50.61 10.69 ... Wind_df.reset_index(inplace=True) # 重置索引 ... Wind_df['index'] = Wind_df['index'].astype(str) # 转换为DatetimeIndex格式 ... Wind_df = Wind_df.rename(columns={'index': '成交日期'}) ... Wind_df.set_index('成交日期', inplace=True) # 设置index列为索引 ... # 对每个组合中的每个证券,按照持仓日期进行合并, ... df_merge = pd.merge(group, Wind_df, left_index=True, right_index=True, how='outer') # 按index来合并 ... # 用之前数据填充 ... for column in columns_to_fill: ... df_merge[column].fillna(method='ffill', inplace=True) # 用前一个非空值填充当前的空值 ... df_merge = df_merge.dropna(how='all') # 删除所有都是NAN的空行 ... df_merge = df_merge.reset_index()# 将df索引持仓日期恢复为数据列 ... df_merge.to_sql(file_namestr, conn, if_exists='append', index=True) # 将df追加入SQLite数据库 ... print('合并完成:', group_name) ... # 打印当前group_name在grouped中的位置 ... index += 1 ... print(f"当前进度:{index}/{total}") ... Traceback (most recent call last): File "pandas\_libs\index.pyx", line 439, in pandas._libs.index.DatetimeEngine.get_loc File "pandas\_libs\index.pyx", line 403, in pandas._libs.index.DatetimeEngine._unbox_scalar TypeError: 0 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 3, in <module> File "C:\Users\Alex\AppData\Roaming\Python\Python310\site-packages\pandas\core\indexing.py", line 2275, in __getitem__ return super().__getitem__(key) File "C:\Users\Alex\AppData\Roaming\Python\Python310\site-packages\pandas\core\indexing.py", line 2222, in __getitem__ return self.obj._get_value(*key, takeable=self._takeable) File "C:\Users\Alex\AppData\Roaming\Python\Python310\site-packages\pandas\core\frame.py", line 3579, in _get_value loc = engine.get_loc(index) File "pandas\_libs\index.pyx", line 429, in pandas._libs.index.DatetimeEngine.get_loc File "pandas\_libs\index.pyx", line 441, in pandas._libs.index.DatetimeEngine.get_loc KeyError: 0
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无人交流的问题

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值