facebook

Hibernate HashSet() help

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #248847 Reply

    SEanLon11
    Member

    I am looking for a good explanation on how to use the getters and setters for the HashSet()’s that are produced with MyEclipse. I have a few errors in my code, but I can not even try to help myself yet b/c I do not completely understand how it works. If anyone could give me a quick synopsis of it, or point me in the right direction, I would appreciate it.

    Thanks,
    Sean

    (And yes, I do have “Hibernate In Action”, and I can not find anything in this book that has helped me yet on this subject)

    #248852 Reply

    Haris Peco
    Member

    Sean,

    You have to send us more details.What is generated files and what is your problem ?

    Best

    #248855 Reply

    SEanLon11
    Member

    Well, there is not really a problem. I am just trying to better understand how the Set that is generated by MyEclipse works. For example, I have the following Schema:

    A table of Contacts:

    
    
    CREATE TABLE contacts (
        contactID      SERIAL PRIMARY KEY,
        gender         TEXT NOT NULL,
        socialTitle    TEXT NULL,
        firstName      TEXT NOT NULL,
        middleName     TEXT NULL,
        lastName       TEXT NOT NULL,
        suffix         TEXT NULL,
        email          TEXT NULL,
        startDate      DATE DEFAULT current_date NOT NULL,
        birthdate      DATE NULL,
        age            INTEGER NULL,
        status         TEXT DEFAULT 'F' NULL -- this from Char to Text 
    );
    
    

    A table of Phones:

    
    
    CREATE TABLE phones (
        phoneID        SERIAL PRIMARY KEY,
        phoneNo        TEXT NOT NULL,
        description    TEXT DEFAULT NULL
    );
    
    

    And a table of Contacts and Phones:

    
    CREATE TABLE contacts_phones (
        phoneID        INTEGER REFERENCES phones(phoneID),
        contactID      INTEGER REFERENCES contacts(contactID), 
        
        PRIMARY KEY(phoneID, contactID)
    ); 
    

    When I generate the code using MyEclipse, I get the following classes:

    AbstractContact (There are other tables that generate extra code in this class, but let’s just focus on the Contact-Phone relationship)

    
    package dbclasses.contacts;
    
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
    
    /**
     * AbstractContact generated by MyEclipse - Hibernate Tools
     */
    
    public abstract class AbstractContact implements java.io.Serializable
    {
    
        // Fields
    
        private Integer contactid;
    
        private String gender;
    
        private String socialtitle;
    
        private String firstname;
    
        private String middlename;
    
        private String lastname;
    
        private String suffix;
    
        private String email;
    
        private Date startdate;
    
        private Date birthdate;
    
        private Integer age;
    
        private String status;
    
        private Set noteses = new HashSet(0);
    
        private Set contactsPhoneses = new HashSet(0);
    
        private Set studentses = new HashSet(0);
    
        private Set otheremployeeses = new HashSet(0);
    
        private Set contactsContactsesForContactid1 = new HashSet(0);
    
        private Set fulltimerses = new HashSet(0);
    
        private Set schoolteacherses = new HashSet(0);
    
        private Set contactsAddresseses = new HashSet(0);
    
        private Set contactsContactsesForContactid = new HashSet(0);
    
        private Set employeeServiceses = new HashSet(0);
    
        private Set instructorses = new HashSet(0);
    
        private Set studentsServiceses = new HashSet(0);
    
        private Set clientses = new HashSet(0);
    
        private Set employeeses = new HashSet(0);
    
        private Set contactsOrganizationses = new HashSet(0);
    
        // Constructors
    
        /** default constructor */
        public AbstractContact()
        {
        }
    
        /** minimal constructor */
        public AbstractContact(String gender, String firstname, String lastname,
                Date startdate)
        {
            this.gender = gender;
            this.firstname = firstname;
            this.lastname = lastname;
            this.startdate = startdate;
        }
    
        /** full constructor */
        public AbstractContact(String gender, String socialtitle, String firstname,
                String middlename, String lastname, String suffix, String email,
                Date startdate, Date birthdate, Integer age, String status,
                Set noteses, Set contactsPhoneses, Set studentses,
                Set otheremployeeses, Set contactsContactsesForContactid1,
                Set fulltimerses, Set schoolteacherses, Set contactsAddresseses,
                Set contactsContactsesForContactid, Set employeeServiceses,
                Set instructorses, Set studentsServiceses, Set clientses,
                Set employeeses, Set contactsOrganizationses)
        {
            this.gender = gender;
            this.socialtitle = socialtitle;
            this.firstname = firstname;
            this.middlename = middlename;
            this.lastname = lastname;
            this.suffix = suffix;
            this.email = email;
            this.startdate = startdate;
            this.birthdate = birthdate;
            this.age = age;
            this.status = status;
            this.noteses = noteses;
            this.contactsPhoneses = contactsPhoneses;
            this.studentses = studentses;
            this.otheremployeeses = otheremployeeses;
            this.contactsContactsesForContactid1 = contactsContactsesForContactid1;
            this.fulltimerses = fulltimerses;
            this.schoolteacherses = schoolteacherses;
            this.contactsAddresseses = contactsAddresseses;
            this.contactsContactsesForContactid = contactsContactsesForContactid;
            this.employeeServiceses = employeeServiceses;
            this.instructorses = instructorses;
            this.studentsServiceses = studentsServiceses;
            this.clientses = clientses;
            this.employeeses = employeeses;
            this.contactsOrganizationses = contactsOrganizationses;
        }
    
        // Property accessors
    
        public Integer getContactid()
        {
            return this.contactid;
        }
    
        public void setContactid(Integer contactid)
        {
            this.contactid = contactid;
        }
    
        public String getGender()
        {
            return this.gender;
        }
    
        public void setGender(String gender)
        {
            this.gender = gender;
        }
    
        public String getSocialtitle()
        {
            return this.socialtitle;
        }
    
        public void setSocialtitle(String socialtitle)
        {
            this.socialtitle = socialtitle;
        }
    
        public String getFirstname()
        {
            return this.firstname;
        }
    
        public void setFirstname(String firstname)
        {
            this.firstname = firstname;
        }
    
        public String getMiddlename()
        {
            return this.middlename;
        }
    
        public void setMiddlename(String middlename)
        {
            this.middlename = middlename;
        }
    
        public String getLastname()
        {
            return this.lastname;
        }
    
        public void setLastname(String lastname)
        {
            this.lastname = lastname;
        }
    
        public String getSuffix()
        {
            return this.suffix;
        }
    
        public void setSuffix(String suffix)
        {
            this.suffix = suffix;
        }
    
        public String getEmail()
        {
            return this.email;
        }
    
        public void setEmail(String email)
        {
            this.email = email;
        }
    
        public Date getStartdate()
        {
            return this.startdate;
        }
    
        public void setStartdate(Date startdate)
        {
            this.startdate = startdate;
        }
    
        public Date getBirthdate()
        {
            return this.birthdate;
        }
    
        public void setBirthdate(Date birthdate)
        {
            this.birthdate = birthdate;
        }
    
        public Integer getAge()
        {
            return this.age;
        }
    
        public void setAge(Integer age)
        {
            this.age = age;
        }
    
        public String getStatus()
        {
            return this.status;
        }
    
        public void setStatus(String status)
        {
            this.status = status;
        }
    
        public Set getNoteses()
        {
            return this.noteses;
        }
    
        public void setNoteses(Set noteses)
        {
            this.noteses = noteses;
        }
    
        public Set getContactsPhoneses()
        {
            return this.contactsPhoneses;
        }
    
        public void setContactsPhoneses(Set contactsPhoneses)
        {
            this.contactsPhoneses = contactsPhoneses;
        }
    
        public Set getStudentses()
        {
            return this.studentses;
        }
    
        public void setStudentses(Set studentses)
        {
            this.studentses = studentses;
        }
    
        public Set getOtheremployeeses()
        {
            return this.otheremployeeses;
        }
    
        public void setOtheremployeeses(Set otheremployeeses)
        {
            this.otheremployeeses = otheremployeeses;
        }
    
        public Set getContactsContactsesForContactid1()
        {
            return this.contactsContactsesForContactid1;
        }
    
        public void setContactsContactsesForContactid1(
                Set contactsContactsesForContactid1)
        {
            this.contactsContactsesForContactid1 = contactsContactsesForContactid1;
        }
    
        public Set getFulltimerses()
        {
            return this.fulltimerses;
        }
    
        public void setFulltimerses(Set fulltimerses)
        {
            this.fulltimerses = fulltimerses;
        }
    
        public Set getSchoolteacherses()
        {
            return this.schoolteacherses;
        }
    
        public void setSchoolteacherses(Set schoolteacherses)
        {
            this.schoolteacherses = schoolteacherses;
        }
    
        public Set getContactsAddresseses()
        {
            return this.contactsAddresseses;
        }
    
        public void setContactsAddresseses(Set contactsAddresseses)
        {
            this.contactsAddresseses = contactsAddresseses;
        }
    
        public Set getContactsContactsesForContactid()
        {
            return this.contactsContactsesForContactid;
        }
    
        public void setContactsContactsesForContactid(
                Set contactsContactsesForContactid)
        {
            this.contactsContactsesForContactid = contactsContactsesForContactid;
        }
    
        public Set getEmployeeServiceses()
        {
            return this.employeeServiceses;
        }
    
        public void setEmployeeServiceses(Set employeeServiceses)
        {
            this.employeeServiceses = employeeServiceses;
        }
    
        public Set getInstructorses()
        {
            return this.instructorses;
        }
    
        public void setInstructorses(Set instructorses)
        {
            this.instructorses = instructorses;
        }
    
        public Set getStudentsServiceses()
        {
            return this.studentsServiceses;
        }
    
        public void setStudentsServiceses(Set studentsServiceses)
        {
            this.studentsServiceses = studentsServiceses;
        }
    
        public Set getClientses()
        {
            return this.clientses;
        }
    
        public void setClientses(Set clientses)
        {
            this.clientses = clientses;
        }
    
        public Set getEmployeeses()
        {
            return this.employeeses;
        }
    
        public void setEmployeeses(Set employeeses)
        {
            this.employeeses = employeeses;
        }
    
        public Set getContactsOrganizationses()
        {
            return this.contactsOrganizationses;
        }
    
        public void setContactsOrganizationses(Set contactsOrganizationses)
        {
            this.contactsOrganizationses = contactsOrganizationses;
        }
    
    }
    

    Here is the Contact_Phone.java

    
    package dbclasses.phones;
    
    // Generated by MyEclipse - Hibernate Tools
    
    /**
     * Contact_Phone generated by MyEclipse - Hibernate Tools
     */
    public class Contact_Phone extends AbstractContact_Phone implements
            java.io.Serializable
    {
    
        // Constructors
    
        /** default constructor */
        public Contact_Phone()
        {
        }
    
        /** full constructor */
        public Contact_Phone(Contact_PhoneId id)
        {
            super(id);
        }
    
    }
    
    

    The AbstractPhone.java

    
    package dbclasses.phones;
    
    import java.util.HashSet;
    import java.util.Set;
    
    /**
     * AbstractPhone generated by MyEclipse - Hibernate Tools
     */
    
    public abstract class AbstractPhone implements java.io.Serializable
    {
    
        // Fields
    
        private Integer phoneid;
    
        private String phoneno;
    
        private String description;
    
        private Set organizationsPhoneses = new HashSet(0);
    
        private Set contactsPhoneses = new HashSet(0);
    
        // Constructors
    
        /** default constructor */
        public AbstractPhone()
        {
        }
    
        /** minimal constructor */
        public AbstractPhone(String phoneno)
        {
            this.phoneno = phoneno;
        }
    
        /** full constructor */
        public AbstractPhone(String phoneno, String description,
                Set organizationsPhoneses, Set contactsPhoneses)
        {
            this.phoneno = phoneno;
            this.description = description;
            this.organizationsPhoneses = organizationsPhoneses;
            this.contactsPhoneses = contactsPhoneses;
        }
    
        // Property accessors
    
        public Integer getPhoneid()
        {
            return this.phoneid;
        }
    
        public void setPhoneid(Integer phoneid)
        {
            this.phoneid = phoneid;
        }
    
        public String getPhoneno()
        {
            return this.phoneno;
        }
    
        public void setPhoneno(String phoneno)
        {
            this.phoneno = phoneno;
        }
    
        public String getDescription()
        {
            return this.description;
        }
    
        public void setDescription(String description)
        {
            this.description = description;
        }
    
        public Set getOrganizationsPhoneses()
        {
            return this.organizationsPhoneses;
        }
    
        public void setOrganizationsPhoneses(Set organizationsPhoneses)
        {
            this.organizationsPhoneses = organizationsPhoneses;
        }
    
        public Set getContactsPhoneses()
        {
            return this.contactsPhoneses;
        }
    
        public void setContactsPhoneses(Set contactsPhoneses)
        {
            this.contactsPhoneses = contactsPhoneses;
        }
    
    }
    

    The Contact_PhoneId.java

    
    package dbclasses.phones;
    
    import dbclasses.contacts.Contact;
    
    /**
     * Contact_PhoneId generated by MyEclipse - Hibernate Tools
     */
    
    public class Contact_PhoneId implements java.io.Serializable
    {
    
        // Fields
    
        private Phone phones;
    
        private Contact contacts;
    
        // Constructors
    
        /** default constructor */
        public Contact_PhoneId()
        {
        }
    
        // Property accessors
    
        public Phone getPhones()
        {
            return this.phones;
        }
    
        public void setPhones(Phone phones)
        {
            this.phones = phones;
        }
    
        public Contact getContacts()
        {
            return this.contacts;
        }
    
        public void setContacts(Contact contacts)
        {
            this.contacts = contacts;
        }
    
        public boolean equals(Object other)
        {
            if ((this == other))
                return true;
            if ((other == null))
                return false;
            if (!(other instanceof Contact_PhoneId))
                return false;
            Contact_PhoneId castOther = (Contact_PhoneId) other;
    
            return ((this.getPhones() == castOther.getPhones()) || (this
                    .getPhones() != null
                    && castOther.getPhones() != null && this.getPhones().equals(
                    castOther.getPhones())))
                    && ((this.getContacts() == castOther.getContacts()) || (this
                            .getContacts() != null
                            && castOther.getContacts() != null && this
                            .getContacts().equals(castOther.getContacts())));
        }
    
        public int hashCode()
        {
            int result = 17;
    
            result = 37 * result
                    + (getPhones() == null ? 0 : this.getPhones().hashCode());
            result = 37 * result
                    + (getContacts() == null ? 0 : this.getContacts().hashCode());
            return result;
        }
    
    }
    

    There is all the code. All I am trying to do is understand how it all works. The most basic question I have is:
    Every time I add a Contact_Phone relationship to the database, should the ContactsPhoneses Set be updated? Do I have to add this functionalitywith a:

    
    Contact c; 
    c.getContactsPhonses().add(new Phone("555-555-5555")); 
    

    If you need any more info, please let me know.

    Thanks,
    Sean

    #248858 Reply

    Haris Peco
    Member

    Sean,

    yes, you have to do.Hibernate will automatic map your beans to databases tables and MyEclipse will make your mappings and POJO for you, but you have to make your buissines functions

    Best

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Hibernate HashSet() help

You must be logged in to post in the forum log in