![](/img/trans.png)
[英]Error javax.validation.ConstraintViolationException
[英]javax.validation.ConstraintViolationException, ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=
我尝试通过使用Hibernate保存DocumentType类的对象。
在客户端(使用Angular js),我像这样传递现场工作流程 (我只能传递工作流程对象的ID):
<input type="hidden" data-ng-model="refRecord.workflow.id" value="2" data-ng-init="refRecord.workflow.id=2"/>
保存对象时,我得到:
javax.validation.ConstraintViolationException, ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=workflow
类DocumentType:
@Entity
@Table(name = "${subsystem.table.prefix}_ref_document_type")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@JsonIgnoreProperties({"new", "workflow", "docClass", "parentTypes", "cacheNames"})
@AttributeOverride(
name = "rowId",
column = @Column(name = "uniqueid", insertable = false, updatable = false)
)
public class DocumentType extends AbstractPeriodCodeReference<String> {
public static final String CACHE_NAME = "documentTypes";
@Override
public String[] getCacheNames() {
return new String[]{CACHE_NAME};
}
@Getter
@Setter
@NotBlank
@Column(nullable = false, length = 512)
private String name;
@Getter
@Setter
@NotBlank
@Column(nullable = false)
private String shortName;
@Getter
@Setter
@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "subtype_id", nullable = false)
private DocumentSubtype subtype;
@Getter
@Setter
@NotNull
@Type(
type = HibernateIntegerEnumType.CLASS_NAME,
parameters = @Parameter(name = HibernateIntegerEnumType.PARAMETER_NAME, value = TypeDocumentEnum.ENUM_CLASS)
)
@Column(nullable = false, name = "in_out", columnDefinition = "number(1,0)")
private TypeDocumentEnum inout;
@Getter
@Setter
@NotNull
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "workflow_id", nullable = false)
private Workflow workflow;
@Getter
@Setter
@Column(nullable = false)
private boolean docflowable;
@Getter
@Column(nullable = false)
private boolean creatable;
@Getter
@ManyToOne(optional = true, cascade = CascadeType.ALL)
@JoinColumn(name = "docflow_code", nullable = true)
private DocflowType docflowType;
@Getter
@OneToMany(mappedBy = "type", fetch = FetchType.LAZY)
private Set<TypeParentDocument> parentTypes = Sets.newHashSet();
@Getter
@Formula("'(' || code || ') ' || name")
private String fullName;
@Getter
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "core_ref_doc_signer_type",
joinColumns = @JoinColumn(name = "doc_code"),
inverseJoinColumns = @JoinColumn(name = "type_id")
)
private Set<SignerType> signerTypes = Sets.newHashSet();
@Getter
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "core_ref_subsystem_doc_type",
joinColumns = @JoinColumn(name = "doc_code"),
inverseJoinColumns = @JoinColumn(name = "subsystem_id")
)
private Set<Subsystem> subsystems = Sets.newHashSet();
public DocumentType(String code) {
Validate.notBlank(code);
this.setCode(code);
}
}
班级工作流程:
@Entity
@Table(name = "core_workflow")
@Immutable
@Getter
public class Workflow extends AbstractSortableEntity<Integer> {
@NotBlank
@Column(nullable = false)
private String name;
@NotEmpty
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "${subsystem.table.prefix}_initial_workflow_status",
joinColumns = @JoinColumn(name = "workflow_id", nullable = false),
inverseJoinColumns = @JoinColumn(name = "status_id", nullable = false)
)
private Set<Status> initialStatuses;
@OneToMany(mappedBy = "pk.workflow", fetch = FetchType.LAZY)
private Set<WorkflowTransition> transitions;
}
我究竟做错了什么?
在AngularJS方面,不建议使用ngInit。 尝试在控制器中设置值,并且仅使用ngModel。 请确保与{{}}一起显示,并检查请求以进行保存时再次检查。 在Java方面,以调试模式运行以查看是否收到了消息以及为什么工作流中未填充任何消息。 显然,根据验证错误,它为null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.