Now that we've seen how SeamGen helps us to configure persistence in our applications, let's take a look at how we can persist Java entities into a relational database.
The Seam Framework makes persisting entities or POJOs to relational databases much easier than executing SQL directly against the database. For an object to persist as an entity, there are several requirements that the POJO must enforce, as defined in the Java EE tutorial (http://java.sun.com/javaee/5/docs/tutorial/doc/bnbqa.html).
The class must be annotated with the
@Entity
annotation, as defined in thejavax.persistence.Entity
class.The class must not have a private no-argument constructor. If you have not explicitly defined a no-argument constructor in a class, then the class will inherently have one.
The class must not be declared as
final
.Entity properties must be accessible via getter and setter methods.
Let's take a look at a simple Java class that can be persisted to the database...