无法通过反射设置字段值错误

huangapple 未分类评论45阅读模式
英文:

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&lt;PropertyName&gt;() and set&lt;PropertyName&gt;() 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]
.

huangapple
  • 本文由 发表于 2020年4月4日 19:55:07
  • 转载请务必保留本文链接:https://java.coder-hub.com/61027679.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定