英文:
Could not set field value by reflection error
问题
我有一个如下所示的类:
import lombok.Getter;
import lombok.Setter;
import org.framework.model.core.baseInfo.SubSystemType;
import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
@Entity
@Table(name = "CORE_POWER_TYPE_DOCUMENT")
@PrimaryKeyJoinColumn(name = "Base_Power_Type_Id")
@Getter
@Setter
public class StoragePowerType extends BasePowerType {
@Override
public SubSystemType getsystemType() {
return SubSystemType.storing;
}
}
以下异常被抛出:
"无法通过反射设置字段值[org.model.core.power.type.StoragePowerType@203cb33d]"
你知道问题是什么吗?
英文:
I have a class like below:
import lombok.Getter;
import lombok.Setter;
import org.framework.model.core.baseInfo.SubSystemType;
import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
@Entity
@Table(name = "CORE_POWER_TYPE_DOCUMENT")
@PrimaryKeyJoinColumn(name = "Base_Power_Type_Id")
@Getter
@Setter
public class StoragePowerType extends BasePowerType {
@Override
public SubSystemType getsystemType() {
return SubSystemType.storing;
}
}
and below exception id throwed:
"****counld not set field value [org.model.core.power.type.StoragePowerType@203cb33d] value by reflection ****"
Do you know what is the problem??
答案1
得分: 0
Most likely some property inside BasePowerType
is declared as private
, with no getter and setter.
Each property of JPA entity must either be public
or have methods get<PropertyName>()
and set<PropertyName>()
defined. Otherwise the framework you are using (Hibernate?) will not be able to access the property.
So use either:
public Long id;
Or:
private Long id;
public Long getId() { return id; }
public void setId(Long value) { id = value; }
Try to follow guidelines from here: Create the perfect JPA entity [closed]
.
英文:
Most likely some property inside BasePowerType
is declared as private
, with no getter and setter.
Each property of JPA entity must either be public
or have methods get<PropertyName>()
and set<PropertyName>()
defined. Otherwise the framework you are using (Hibernate?) will not be able to access the property.
So use either:
public Long id;
Or:
private Long id;
public Long getId() { return id; }
public void setId(Long value) { id = value; }
Try to follow guidelines from here: Create the perfect JPA entity [closed]
.
专注分享java语言的经验与见解,让所有开发者获益!
评论