I'm working on/experimenting at the moment, so here is one of the ways I've used this myself. Three classes: User, UserDate (to be used as a component), BatchStatus (which has several UserDate components in it), and Batch (which has a BatchStatus component).
//USER
Code:
/**
* @author BruceS
* @hibernate.class
*/
public class User implements Serializable {
private Long id;
private String name;
/**
*
*/
public User() {
}
/**
* @hibernate.id generator-class = "native"
* @return Returns the id.
*/
public Long getId() {
return id;
}
/**
* @hibernate.property
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @param id The id to set.
*/
public void setId(Long id) {
this.id = id;
}
/**
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}
}
//USERDATE
Code:
/**
* @author BruceS
* NOTE columns names are in proper case.
* They will be prefixed with lowercase letters where this
* class is used as a component.
*/
public class UserDate {
private User user;
private Date date;
/**
* @hibernate.property
* @hibernate.column name = "Date" sql-type = "datetime" not-null = "false"
* @return Returns the date.
*/
public Date getDate() {
return date;
}
/**
* @hibernate.many-to-one
* @hibernate.column name = "User" not-null = "false"
* @return Returns the user.
*/
public User getUser() {
return user;
}
/**
* @param date The date to set.
*/
public void setDate(Date date) {
this.date = date;
}
/**
* @param user The user to set.
*/
public void setUser(User user) {
this.user = user;
}
}
//BATCHSTATUS
Code:
/**
* @author BruceS
*/
public abstract class BatchStatus {
private UserDate accepted;
private UserDate checked;
private UserDate created;
private UserDate hold;
private UserDate modified;
private UserDate opened;
private UserDate posted;
private UserDate received;
/**
* @hibernate.component prefix = "accepted"
* @return Returns the accepted.
*/
public UserDate getAccepted() {
return accepted;
}
/**
* @hibernate.component prefix = "checked"
* @return Returns the checked.
*/
public UserDate getChecked() {
return checked;
}
/**
* @hibernate.component prefix = "created"
* @return Returns the created.
*/
public UserDate getCreated() {
return created;
}
/**
* @hibernate.component prefix = "hold"
* @return Returns the hold.
*/
public UserDate getHold() {
return hold;
}
/**
* @hibernate.component prefix = "modified"
* @return Returns the modified.
*/
public UserDate getModified() {
return modified;
}
/**
* @hibernate.component prefix = "opened"
* @return Returns the opened.
*/
public UserDate getOpened() {
return opened;
}
/**
* @hibernate.component prefix = "posted"
* @return Returns the posted.
*/
public UserDate getPosted() {
return posted;
}
/**
* @hibernate.component prefix = "received"
* @return Returns the received.
*/
public UserDate getReceived() {
return received;
}
/**
* @param accepted The accepted to set.
*/
public void setAccepted(UserDate accepted) {
this.accepted = accepted;
}
/**
* @param checked The checked to set.
*/
public void setChecked(UserDate checked) {
this.checked = checked;
}
/**
* @param created The created to set.
*/
public void setCreated(UserDate created) {
this.created = created;
}
/**
* @param hold The hold to set.
*/
public void setHold(UserDate hold) {
this.hold = hold;
}
/**
* @param modified The modified to set.
*/
public void setModified(UserDate modified) {
this.modified = modified;
}
/**
* @param opened The opened to set.
*/
public void setOpened(UserDate opened) {
this.opened = opened;
}
/**
* @param posted The posted to set.
*/
public void setPosted(UserDate posted) {
this.posted = posted;
}
/**
* @param received The received to set.
*/
public void setReceived(UserDate received) {
this.received = received;
}
}
//BATCH
Code:
/**
* @author BruceS
* @hibernate.class
*/
public abstract class Batch implements Serializable {
private BatchStatus batchStatus;
private Long id;
/**
* @return Returns the theStatus.
* @hibernate.component
*/
public BatchStatus getBatchStatus() {
return batchStatus;
}
/**
* @hibernate.id generator-class = "native"
* @return Returns the id.
*/
public Long getId() {
return id;
}
/**
* @param theStatus The theStatus to set.
*/
public void setBatchStatus(BatchStatus batchStatus) {
this.batchStatus = batchStatus;
}
/**
* @param id The id to set.
*/
public void setId(Long id) {
this.id = id;
}
}
All the above yields a table schema like this:
create table Batch (
id numeric(19,0) identity not null,
acceptedDate datetime null,
acceptedUser numeric(19,0) null,
checkedDate datetime null,
checkedUser numeric(19,0) null,
createdDate datetime null,
createdUser numeric(19,0) null,
holdDate datetime null,
holdUser numeric(19,0) null,
modifiedDate datetime null,
modifiedUser numeric(19,0) null,
openedDate datetime null,
openedUser numeric(19,0) null,
postedDate datetime null,
postedUser numeric(19,0) null,
receivedDate datetime null,
receivedUser numeric(19,0) null,
primary key (id)
);
Hope this helps.