Reputation: 3750
Having a @MappedSuperClass SomeClass
(see below for a minimal example), is it possible to overwrite a @Pattern
via @AttributeOverride
in SomeOtherclass
that extends SomeClass
?
@MappedSuperClass
public abstract class SomeClass {
@Column(name = "NAME", length = 255, unique = false, nullable = true)
@Pattern(regex = "([a-zA-Z0-9]+_)*([a-zA-Z0-9]+)")
private String name;
…
}
@AttributeOverride(name = "name", column = @Column(name = "NAME", length = 20, unique = false, nullable = false))
public class SomeOtherClass extends SomeClass {
….
}
Or is there any other way to define a new @Pattern
for inherited classes?
Upvotes: 1
Views: 976
Reputation: 80603
This is not possible. The @AttributeOverride and @Pattern annotations are not parts of the same specification.
@AttributeOverride is part of the JPA specification and allows you to override the column definition of a property in an entity subclass.
@Pattern is part of the bean validation (JSR 303) specification and allows you to specify a regular expression to match the annotated member against. You cannot override a @Pattern annotation, but you can cumulatively apply new patterns in subclasses, assuming you are annotating your methods and not your fields.
See this somewhat related answer.
Upvotes: 2