What is the difference between Entity and Persistent class?

I am going through the Hibernate Documentation where the author used the terms persistent class to refer to entities.

The author says, Not all user-defined classes with a persistent state, however, are entities...

I am unable to differentiate between the two. Please suggest.

Upvotes: 2

Views: 1778

Answers (1)

Ken Chan
Ken Chan

Reputation: 90447

Hibernate defines the persistent class as any classes that can be persisted to the database.

There are two types of persistent classes : entity type and value type . So entity is one type of the persistent class.

Entity type are those classes that are marked with @Entity while value type are those classes marked with @Embeddable or some basic Java type such as String , Integer , Date etc.

The main difference between them is that value type does not define their own life-cycle.They are "owned" by entity type which defines their life-cycle.

We create an entity type class which contains many value type classes.

Upvotes: 2

Related Questions