gpt4 book ai didi

java - 映射异常 : "No property found on entity to bind constructor parameter to"?

转载 作者:可可西里 更新时间:2023-11-01 10:48:20 25 4
gpt4 key购买 nike

我的项目是用spring data mongodb开发的,以前有这个文档:

@Document(collection="Instrument")
public class Instrument {
@Id
private Integer id;

private String name;

private String internalCode;

private String fosMarketId;

private String localCode;

//setters...getters... and constructurs....

现在我需要向我的文档添加一些属性,如下所示:

....

private Long from;

private Long to;

private Long OpenHourfrom;

private Long OpenHourTo;

private Boolean isActive;

//setters...getters... and constructurs....

所以我有了这个新的构造函数:

    @PersistenceConstructor
public Instrument(Integer id, String name, String internalCode, String fosMarketId, String localCode, Long from,
Long to, Long openHourfrom, Long openHourTo, Boolean isActive) {
super();
this.id = id;
this.name = name;
this.internalCode = internalCode;
this.fosMarketId = fosMarketId;
this.localCode = localCode;
this.from = from;
this.to = to;
this.OpenHourfrom = openHourfrom;
this.OpenHourTo = openHourTo;
this.isActive = isActive;
}

但是当我运行其中一个 repo 方法时,这个异常被抛出:

org.springframework.data.mapping.model.MappingException: No property openHourfrom found on entity class com.tosan.entity.Instrument to bind constructor parameter to!
at org.springframework.data.mapping.model.PersistentEntityParameterValueProvider.getParameterValue(PersistentEntityParameterValueProvider.java:74)
at ....

请注意,我使用带有以下设置的 spring-confix.xml:

    <mongo:mongo-client 
host="IP" port="Port" >
<mongo:client-options write-concern="NORMAL"
connections-per-host="1000"
threads-allowed-to-block-for-connection-multiplier="600"
connect-timeout="10000"
max-wait-time="15000"
socket-keep-alive="true"
socket-timeout="15000"
/>
</mongo:mongo-client>

我想知道如何将 hibernate spring 的自动更新属性设置为 true,以便我可以更新我的文档并添加新属性。

最佳答案

  1. 使用import org.springframework.data.mongodb.core.mapping.Field;@Field 每个字段的注释

  2. 检查实体类的构造函数并确保参数名称正确

关于java - 映射异常 : "No property found on entity to bind constructor parameter to"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47387143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com