Hi guys,
I dont actually have any mapping files, we use annotations to automatically create the tables. Here is the group bean if it helps.
Code:
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.CollectionOfElements;
@Entity
public class Group implements Serializable
{
/**
* Serializable ID
*/
private static final long serialVersionUID = 1L;
/**
* Hibernate primary key
*/
private long id;
/**
* Name of the Group
*/
private String name;
/**
* Description of the Group
*/
private String description;
/**
* Owner of the Group
*/
private String owner;
/**
* Time that group was created
*/
private Timestamp creationTime = new Timestamp(System.currentTimeMillis());
/**
* The type of group
*/
private GroupType groupType;
/**
* Group
* This key value pair, is the member and true of false to indicate if the User is visible.
* If the Boolean part of the HashMap (the value) is TRUE then the User (the Key) is visible to the group,
* otherwise the User is NOT visible.
*/
public Map<String, Boolean> members = new HashMap<String, Boolean>();
/**
* Default Constructor.
*
*/
public Group()
{
super();
members = new HashMap<String, Boolean>();
}
/**
* Constructor for Creating groups
* PRECONDITIONS: None of the parameters can be NULL.
* @param owner
* @param name
* @param description
* @param groupType
*/
public Group(String owner, final String name, String description, final GroupType groupType)
{
super();
if(StringUtils.isBlank(owner))
{
throw new IllegalArgumentException("Group owner must not be NULL");
}
if(StringUtils.isBlank(name))
{
throw new IllegalArgumentException("Group name must not be NULL");
}
if(groupType == null)
{
throw new IllegalArgumentException("Group TYPE must not be NULL");
}
if(description == null)
{
description = "";
}
this.owner = owner;
this.name = name;
this.description = description;
this.groupType = groupType;
this.members.put(owner, Boolean.TRUE); // add the owner to the members list
}
// Getter and Setter Methods ///////////////////////////////////////////////////////
public Timestamp getCreationTime()
{
return creationTime;
}
public void setCreationTime(final Timestamp creationTime)
{
if(creationTime == null)
{
throw new IllegalArgumentException("Group creationTime must not be NULL");
}
this.creationTime = creationTime;
}
public String getOwner()
{
return owner;
}
public void setOwner(final String owner)
{
if(StringUtils.isBlank(owner))
{
throw new IllegalArgumentException("Group owner must not be NULL");
}
this.owner = owner;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
if(description == null)
{
description = "";
}
this.description = description;
}
public GroupType getGroupType()
{
return groupType;
}
public void setGroupType(final GroupType groupType)
{
if(groupType == null)
{
throw new IllegalArgumentException("Group TYPE must not be NULL");
}
this.groupType = groupType;
}
@Id
@GeneratedValue
public long getId()
{
return id;
}
public void setId(final long id)
{
this.id = id;
}
/**
* Get list of members who are in this group.
* @return
*/
@CollectionOfElements(fetch = FetchType.EAGER)
public Map<String, Boolean> getMembers()
{
return members;
}
public void setMembers(final Map<String, Boolean> members)
{
if(members == null)
{
throw new IllegalArgumentException("Group Members must not be NULL");
}
this.members = members;
}
/**
* Name of the group
* @return
*/
@Column(nullable = false, unique = true)
public String getName()
{
return name;
}
public void setName(final String name)
{
if(StringUtils.isBlank(name))
{
throw new IllegalArgumentException("Group name must not be NULL");
}
this.name = name;
}
/**
* String Method for Group
*/
public String toString()
{
String retString = name + " : " + description;
return retString;
}
}
So this code creates a group table and a group_members table which links to the group table via the group_id.
Hope that helps.
Thanks, Scott.