logo

JPA (EclipseLink, Hibernate) entity explained.

JPA (EclipseLink, Hibernate) entity explained. Mapping table to an entity and table column to an attribute.

What is an entity? It's a POJO class, that is annotated with @Entity annotation and is mapped to a database table. It must have a default constructor and it's best practice that it should implement Serializable interface.

By default the name of the entity is the same as the name of the table in database. If if differs, you must add before class annotation @Table and inside it specify the table name.

Table in database has columns. These columns are mapped to attributes in entity. By default the name of the attribute is the same as the name of the column in database table. If it differs, you must add before attribute annotation @Column and inside it specify the column name.

If you have an attribute that isn't mapped to a table column, add before such attribute annotation @Transient.

Attributes must have getters and setters.


comments powered by Disqus

rss

Free online Java web application examples

Want to develop whole web applications which use database, security and more? See my github account, where are lot's of example projects:
github

Search