3.5.4.3. Property Based Entity Bean Class Example (EJB 3)
@Entity public class AnEntity
{
// With property based access fields are not persistent themselves.
private int someTransientField;
private String someOtherTransientField;
// Relationships among entities must be annotated.
private Collection<AnotherEntity> relatedEntities;
@OneToMany public Collection<AnotherEntity> getRelatedEntities ()
{
return (relatedEntities);
}
public void setRelatedEntities (Collection<AnotherEntity> entityCollection)
{
relatedEntities = entityCollection;
}
// Getter and setter methods for primary key.
private long aKeyField;
@Id Long getAKeyField () { return (aKeyField); }
public void setAKeyField (Long aKeyField) { this.aKeyField = aKeyField; }
// Obligatory constructor with no arguments
public AnEntity () { ... }
// Additional business methods ...
public void myMethodOne (int iArgument) { ... }
public int myMethodTwo (Object oArgument) { ... }
}