gpt4 book ai didi

java - 如何解决 "IllegalArgumentException occurred while calling setter for property"?

转载 作者:行者123 更新时间:2023-11-30 08:02:42 27 4
gpt4 key购买 nike

我正在尝试使用条件从消息表中获取所有条目

Criteria getCriteria = session.createCriteria(MessageAttributes.class);
List<MessageAttributes> unProcessedJcbMessagesList=getCriteria.list();

当我尝试运行高于标准时,出现以下异常。FieldId 是来自AvailableFields(AvailableFieldsIs) 表的外键。

  IllegalArgumentException occurred while calling setter for property [com.alu.jcb.model.MessageAttributes.fieldId (expected type = com.alu.jcb.model.AvailableFields)]; target = [com.alu.jcb.model.MessageAttributes@1cf3877], property value = [2]
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:123)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:713)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:362)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:4718)
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:188)
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:144)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1115)
at org.hibernate.loader.Loader.processResultSet(Loader.java:973)
at org.hibernate.loader.Loader.doQuery(Loader.java:921)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
at org.hibernate.loader.Loader.doList(Loader.java:2554)
at org.hibernate.loader.Loader.doList(Loader.java:2540)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
at org.hibernate.loader.Loader.list(Loader.java:2365)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:126)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1718)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:380)
at com.alu.jcb.messageProcessor.Test.main(Test.java:23)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:68)
... 17 more

bean 类

MessageAttributes.java

public class MessageAttributes {
private long messageAttributeId=1L;
private AvailableFields fieldId;
private String value;
//getters and setters
}

AvailableFields.java

public class AvailableFields {

private long availableFieldsId=1L;
private Instance instance;
private String fieldDisplayName;

//getters and setters
}

HBM 文件MessageAttributes.hbm.xml

<hibernate-mapping package="com.alu.jcb.model">
<class name="MessageAttributes" table="MESSAGE_ATTRIBUTES">
<id name="messageAttributeId" column="message_attribute_id" type="long">
<generator class="sequence" />
</id>

<many-to-one name="fieldId" class="com.alu.jcb.model.AvailableFields" fetch="select">
<column name="field_id" not-null="true" />
</many-to-one>

<property name="value" type="string" column="value" />
</class>
</hibernate-mapping>

AvailableFields.hbm.xml

<hibernate-mapping package="com.alu.jcb.model">
<class name="AvailableFields" table="AVAILABLE_FIELDS">
<id name="availableFieldsId" column="available_fields_id" type="java.lang.Long">
<generator class="sequence" />
</id>
<many-to-one name="instance" class="com.alu.jcb.model.Instance" fetch="select">
<column name="instance_id" not-null="true" />
</many-to-one>
<property name="fieldDisplayName" type="string" column="field_display_name" not-null="true"/>
</class>
</hibernate-mapping>

请帮助我

最佳答案

该错误表示 fieldId 的 setter 出现问题。应该是这样的

public void setFieldId(AvailableFields fieldId) {
this.fieldId=fieldId;
}

但在你的情况下,setter 中使用了不正确的类(猜测很长)。

关于java - 如何解决 "IllegalArgumentException occurred while calling setter for property"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31645493/

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