0 Replies Latest reply on Sep 12, 2006 5:39 AM by Eric Chow

    hbm.xml

    Eric Chow Apprentice

      Hello,

      As I am a beginner in Hibernate and I usually used Annotated classes. I am now going to tried hbm.xml. Could you please to tell me how I can convert the following annotated classes into hbm.xml ?

      package mo.putoweb.model.account;
      
      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.Collection;
      
      import javax.persistence.CascadeType;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.JoinTable;
      import javax.persistence.ManyToMany;
      import javax.persistence.Transient;
      
      @Entity
      public class User implements Serializable {
       public static final long serialVersionUID = 1L;
      
       private String username;
      
       private String password;
      
      
       private String firstName;
       private String lastName;
       private String displayName;
       private String gender;
      
      
       private boolean activate;
      
       private Collection<Role> roles = new ArrayList<Role>();
       private Collection<Group> groups = new ArrayList<Group>();
      
      
       @Transient
       public boolean isActivate() {
       return activate;
       }
      
      
       public boolean getActivate() {
       return activate;
       }
      
       public void setActivate(boolean activate) {
       this.activate = activate;
       }
      
       public String getPassword() {
       return password;
       }
      
       public void setPassword(String password) {
       this.password = password;
       }
      
       @Id
       //@GeneratedValue(strategy = GenerationType.AUTO)
       public String getUsername() {
       return username;
       }
      
       public void setUsername(String username) {
       this.username = username;
       }
      
      
      
       public String getFirstName() {
       return firstName;
       }
      
       public void setFirstName(String firstName) {
       this.firstName = firstName;
       }
      
       public String getLastName() {
       return lastName;
       }
      
       public void setLastName(String lastName) {
       this.lastName = lastName;
       }
      
      
      
      
       public String getDisplayName() {
       return displayName;
       }
      
       public void setDisplayName(String displayName) {
       this.displayName = displayName;
       }
      
      
      
      
      
       public String getGender() {
       return gender;
       }
      
       public void setGender(String gender) {
       this.gender = gender;
       }
      
       @ManyToMany(cascade = {CascadeType.REMOVE},
       fetch = FetchType.EAGER,
       targetEntity=Role.class)
       @JoinTable(
       name="USER_ROLE_LINK",
       joinColumns={@JoinColumn(name="username")},
       inverseJoinColumns={@JoinColumn(name="rolename")}
       )
       public Collection<Role> getRoles() {
       return roles;
       }
      
       public void setRoles(Collection<Role> roles) {
       this.roles = roles;
       }
      
       @Transient
       public void addRole(Role role) {
       this.roles.add(role);
       }
      
      
       @ManyToMany(cascade = {CascadeType.REMOVE},
       fetch = FetchType.LAZY,
       targetEntity=Group.class)
       @JoinTable(
       name="USER_GROUP_LINK",
       joinColumns={@JoinColumn(name="username")},
       inverseJoinColumns={@JoinColumn(name="groupname")}
       )
       public Collection<Group> getGroups() {
       return groups;
       }
      
      
       public void setGroups(Collection<Group> groups) {
       this.groups = groups;
       }
      
       @Transient
       public void addGroup(Group group) {
       groups.add(group);
       }
      
      }
      



      package mo.putoweb.model.account;
      
      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.Collection;
      
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.JoinTable;
      import javax.persistence.ManyToMany;
      import javax.persistence.Transient;
      
      @Entity
      public class Role implements Serializable {
       public static final long serialVersionUID = 1L;
      
       private String roleName;
       private String description;
      
       private Collection<User> users = new ArrayList<User>();
      
       public String getDescription() {
       return description;
       }
      
       public void setDescription(String description) {
       this.description = description;
       }
      
       @Id
       public String getRoleName() {
       return roleName;
       }
      
       public void setRoleName(String roleName) {
       this.roleName = roleName;
       }
      
       @ManyToMany(
       targetEntity=User.class,
       mappedBy="roles",
       fetch = FetchType.EAGER)
       @JoinTable(
       name="USER_ROLE_LINK",
       joinColumns={@JoinColumn(name="rolename")},
       inverseJoinColumns={@JoinColumn(name="username")}
       )
       public Collection<User> getUsers() {
       return users;
       }
      
       public void setUsers(Collection<User> users) {
       this.users = users;
       }
      
       @Transient
       public void addUser(User user) {
       this.users.add(user);
       }
      
      
      
      
      }
      
      




      package mo.putoweb.model.account;
      
      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.Collection;
      
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.JoinTable;
      import javax.persistence.ManyToMany;
      import javax.persistence.Table;
      import javax.persistence.Transient;
      
      @Entity
      @Table(name = "UserGroup")
      public class Group implements Serializable {
       private static final long serialVersionUID = 1L;
      
       private String groupName;
      
       private String description;
      
       private Collection<User> users = new ArrayList<User>();
      
       public String getDescription() {
       return description;
       }
      
       public void setDescription(String description) {
       this.description = description;
       }
      
       @Id
       public String getGroupName() {
       return groupName;
       }
      
       public void setGroupName(String groupName) {
       this.groupName = groupName;
       }
      
       @ManyToMany(fetch = FetchType.LAZY, mappedBy="groups")
       @JoinTable(
       name="USER_GROUP_LINK",
       joinColumns={@JoinColumn(name="groupname")},
       inverseJoinColumns={@JoinColumn(name="username")}
       )
       public Collection<User> getUsers() {
       return users;
       }
      
       public void setUsers(Collection<User> users) {
       this.users = users;
       }
      
       @Transient
       public void addUser(User user) {
       users.add(user);
       }
      
      }