Hibernate要求枚举

时间:2015-12-02 09:28:52

标签: java hibernate validation enums dropwizard

使用dropwizard和hibernate 我试图坚持下去的例外是

  

无法找到约束的验证程序   'javax.validation.constraints.Size'验证类型   'enums.ServiceType'。检查'type'的配置

代码如下:

@Table(name = "transactions",
        indexes = {
                @Index(name = "references_index", columnList = "reference_id")
        }
)

public class Transaction {

    @JsonIgnore
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private long id;

    @NonNull
    @NotEmpty
    @Column(name = "reference_id", unique = true)
    private String referenceId;

    @NonNull
    @NotEmpty
    @Column(name = "state")
    private String state;

    @NonNull
    @Column(name = "type")
    @Enumerated(EnumType.STRING)
    private ServiceType type;

    @NonNull
    @NotEmpty
    @Column(name = "provider")
    private String provider;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "created_date", insertable = false, updatable = false)
    private Date createdTimeStamp;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_updated", insertable = false, updatable = true)
    private Date updatedTimeStamp;

    public Transaction(String referenceId, String state, ServiceType type, String provider) {
        this.referenceId = referenceId;
        this.state = state;
        this.type = type;
        this.provider = provider;
    }

}

,其中

public enum ServiceType {
    TYPEA, TYPEB, TYPEC
}

坚持DAO

class TransactionDAO extends AbstractDAO<Transaction> {
    /**
     * Creates a new DAO with a given session provider.
     *
     * @param sessionFactory a session provider
     */
    public TransactionDAO(SessionFactory sessionFactory) {
        super(sessionFactory);
    }

      protected Transaction persistTransaction(Transaction transaction) {
        return persist(transaction);
    }
}

1 个答案:

答案 0 :(得分:2)

在我的枚举上添加$products_sku解决了这个问题。但是我不知道为什么错误消息说它正在尝试 javax.validation.constraints.Size

来自工作代码的代码段

@Valid