What Is @repeatable and Why Should You Like It?
What Is @repeatable and Why Should You Like It?
What Is @repeatable and Why Should You Like It?
2
What is @Repeatable and why should you like it?
Sometimes, you want to apply the same annotation multiple times.
Before Java 8, the only way to do that was to use an additional
annotation and provide an array of the annotations you want to apply
as a value.
With Java 8, you can define an annotation as repeatable and apply it
multiple times without any wrapper annotations.
www.thoughts-on-java.org
@Repeatable annotations in Hibernate 5.2
Annotation JavaDoc
JoinColumnOrFormula Allows joins based on column or a
formula. One of formula() or
column() should be specified, but
not both.
NamedNativeQuery Extends NamedNativeQuery with
Hibernate features.
Table Complementary information to a
table either primary or secondary.
Tuplizer Define a tuplizer for an entity or a
component.
TypeDef A type definition. Much like Type,
but here we can centralize the
definition under a name and refer
to that name elsewhere. The
plural form is TypeDefs.
@Entity
@NamedQueries({
@NamedQuery(name = “Book.findByTitle”, query = “SELECT b
FROM Book b WHERE b.title = :title”),
@NamedQuery(name = “Book.findByPublishingDate”, query =
“SELECT b FROM Book b WHERE b.publishingDate =
:publishingDate”)
})
public class Book implements Serializable {
…
}
www.thoughts-on-java.org
@Repeatable annotations in Hibernate 5.2
That’s no longer required, if you use Hibernate’s version of the
@NamedQuery annotation or of any other annotation listed in the
previous section. As you can see in the following code snippet, you
can now add multiple org.hibernate.annotations.NamedQuery
annotations directly to the entity.
@Entity
@NamedQuery(name = “Hibernate5Book.findByTitle”, query =
“SELECT b FROM Hibernate5Book b WHERE b.title = :title”)
@NamedQuery(name = “Hibernate5Book.findByPublishingDate”,
query = “SELECT b FROM Hibernate5Book b WHERE
b.publishingDate = :publishingDate”)
public class Hibernate5Book implements Serializable {
…
}
www.thoughts-on-java.org