gpt4 book ai didi

JPA 状态字段路径无法解析为有效类型

转载 作者:行者123 更新时间:2023-12-04 23:06:04 26 4
gpt4 key购买 nike

我需要帮助解决与 EclipseLink 2.5.x 提供商的关系/查询问题。

从 ThreePhaseMotorInput 到 ValidationMessage 的关系应该是单向的 OneToMany,即每个电机可以有 0..n 条消息,并且在 Java 对象图中 ValidationMessage 没有返回到 ThreePhaseMotorInput 的引用。

我得到一个错误,当通过 ThreePhaseMotor 访问时,JPA 找不到属于 ValidationMessage 类的属性。 (请参阅下面的错误文本)

感谢您考虑我的问题!

查询

select msg.validationMsg, COUNT(m.id) from ThreePhaseMotorInput AS m JOIN m.valMessages AS msg GROUP BY msg.validationMsg

错误

 org.eclipse.persistence.exceptions.JPQLException: 
Exception Description: Problem compiling [select msg.validationMsg, COUNT(m.id) from ThreePhaseMotorInput AS m JOIN m.valMessages AS msg GROUP BY msg.validationMsg].
[7, 24] The state field path 'msg.validationMsg' cannot be resolved to a valid type.
[71, 84] The collection-valued path 'm.valMessages' cannot be resolved to a valid association field.
[119, 136] The state field path 'msg.validationMsg' cannot be resolved to a valid type.

ThreePhaseMotorInput

@Entity
@Table(name = "three_phase_motor_input")
public class ThreePhaseMotorInput implements IThreePhaseMotorInput, Serializable {
private static final long serialVersionUID = 8084370807289186987L;
@Transient
private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Version
private Integer version;
private Integer status;
@Transient
private Integer numMessages;

@OneToOne(cascade = CascadeType.ALL, optional = true, targetEntity = UnapprovedThreePhaseMotor.class)
@JoinColumn(name = "unapproved_id")
private IThreePhaseMotor unapprovedMotor;

@OneToOne(cascade = CascadeType.ALL, optional = true, targetEntity = ApprovedThreePhaseMotor.class)
@JoinColumn(name = "approved_id")
private IThreePhaseMotor approvedMotor;

@OneToMany(orphanRemoval = true, cascade = CascadeType .ALL, fetch = FetchType.LAZY, targetEntity = ValidationMessage.class)
@JoinColumn(name = "input_id", referencedColumnName = "id", nullable = false)
@OrderColumn(name = "idx")
private List<IValidationMessage> valMessages;

ValidationMessage

@Entity
@Table(name = "validation_message")
public class ValidationMessage implements Serializable, IValidationMessage {
private static final long serialVersionUID = 8765213112015434057L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "record_id")
private Long recordId;
@Column(name = "field_name")
private String fieldName;
@Column(name = "validation_msg")
private String validationMsg;
private Integer status;
@Column(name = "fail_field")
private String failField;
@Column(name = "error_source")
private Integer errorSource;

最佳答案

问题似乎出在以下查询中:select m.approvedMotor, m.valMessages, m.valMessages.validationMsg, count(m.valMessages.id) from ThreePhaseMotorInput m group by m.valMessages.validationMsg.

该查询应该是 JPQL 查询,即您指定实体及其 Java 属性的查询。此外,如果您想跳转到另一个实体的属性,则必须使用 JOINs:m.valMessages.validationMsg 不正确,但是 INNER JOIN m.valMessages msg GROUP BY msg 是正确的。

所以试试下面的查询:

select m, COUNT(msg) from ThreePhaseMotorInput AS m LEFT JOIN m.valMessages AS msg GROUP BY msg.validationMsg

关于JPA 状态字段路径无法解析为有效类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28519654/

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