我尝试使用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
Class 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;
}
我做错了什么?
答案 0 :(得分:0)
在AngularJS方面,不建议使用ngInit。尝试在控制器中设置值,仅使用ngModel。用{{}}显示它以确定,并检查保存时要仔细检查的请求。 在java端,在调试模式下运行以查看是否收到了某些内容以及为什么在工作流中没有填充任何内容。显然,根据验证错误,它为空。