简体   繁体   中英

javax.validation.ConstraintViolationException, ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=

I try to save the object of class DocumentType by using Hibernate.

On the client-side (using Angular js) i pass field workflow like that (i can pass only id of workflow object):

 <input type="hidden" data-ng-model="refRecord.workflow.id" value="2" data-ng-init="refRecord.workflow.id=2"/>

While saving an object i get:

 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);
    }
}

Class Workflow:

@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;
}

What am I doing wrong?

On AngularJS side, ngInit is not recommended. Try to set the value in the controller and only use ngModel. Display it with {{}} to be sure, and inspect the request to double check when saving. On java side, run in debug mode to see if something is received and why nothing is populated in workflow. Obviously, it's null according to the validation error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM