Как сохранить спящий объект и игнорировать (не правильный) временный шаблон.
например:
@Entity
@Table(name="`REQUEST`")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="`receiver`",discriminatorType=DiscriminatorType.STRING,length=20)
public abstract class Request implements UUIDAble{
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@Transient
@NotNull
@Pattern(regexp="^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}$")
private String vaucher;
@Enumerated(EnumType.STRING)
@Column(name="name",nullable=false)
private RequestName name;
public RequestName getName() {
return name;
}
public void setName(RequestName name) {
this.name = name;
}
public String getVaucher() {
return vaucher;
}
public void setVaucher(String vaucher) {
this.vaucher = vaucher;
}
}
и я хочу сохранить его:
Request request = new Request();
request.setVaucher("123");
request.setName(RequestName.SYSTEM);
Spring генерирует ошибку:
javax.validation.ConstraintViolationException: validation failed for classes [ru.icb.cpaclick.domain.OperatorCheckRequest] during persist time for groups [javax.validation.groups.Default, ]
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:132)
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:71)
at org.hibernate.action.EntityIdentityInsertAction.preInsert(EntityIdentityInsertAction.java:159)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:65)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)