- This topic has 1 reply, 2 voices, and was last updated 16 years, 2 months ago by Loyal Water.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
arupsarkarMemberHi:
The query string is returning a list which I am trying to display using System.out.println but I am unable to do so. Can someone please help.
I am trying to access the list using the following code, the list size is correct as per the database, I verified it, but how do I get the last name or first name?
Also, if someone could point me to tutorials where they handle hibernate collections many-to-many(update/insert/delete) without struts or spring using myeclipseide would be greatly appreciated any sample code would do.
List contact = contactsDAO.findAll(); System.out.println("List size: " + contact.size()); ContactsId globalContactsId = new ContactsId(); for(int i=0;i<contact.size();i++){ Contacts localContacts = (Contacts)contact.get(i); //globalContactsId = localContacts.getId(); System.out.println(localContacts.getId().toString()); } contactsDAO.getSession().close();
DAO Code:
—————————-public List findAll() { log.debug("finding all Contacts instances"); try { String queryString = "from Contacts"; Query queryObject = getSession().createQuery(queryString); return queryObject.list(); } catch (RuntimeException re) { log.error("find all failed", re); throw re; } }
Contacts.java
—————–public class Contacts extends AbstractContacts implements java.io.Serializable { // Constructors /** default constructor */ public Contacts() { } /** full constructor */ public Contacts(ContactsId id) { super(id); } }
AbstractContacts.java
——————————-public abstract class AbstractContacts implements java.io.Serializable { // Fields private ContactsId id; // Constructors /** default constructor */ public AbstractContacts() { } /** full constructor */ public AbstractContacts(ContactsId id) { this.id = id; } // Property accessors public ContactsId getId() { return this.id; } public void setId(ContactsId id) { this.id = id; } }
ContactsId.java
————————public class ContactsId extends AbstractContactsId implements java.io.Serializable { // Constructors /** default constructor */ public ContactsId() { } /** full constructor */ public ContactsId(Double contactId, String firstName, String middleName, String lastName) { super(contactId, firstName, middleName, lastName); } }
AbstractContactsId.java
—————————–public abstract class AbstractContactsId implements java.io.Serializable { // Fields private Double contactId; private String firstName; private String middleName; private String lastName; // Constructors /** default constructor */ public AbstractContactsId() { } /** full constructor */ public AbstractContactsId(Double contactId, String firstName, String middleName, String lastName) { this.contactId = contactId; this.firstName = firstName; this.middleName = middleName; this.lastName = lastName; } // Property accessors public Double getContactId() { return this.contactId; } public void setContactId(Double contactId) { this.contactId = contactId; } 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 boolean equals(Object other) { if ((this == other)) return true; if ((other == null)) return false; if (!(other instanceof AbstractContactsId)) return false; AbstractContactsId castOther = (AbstractContactsId) other; return ((this.getContactId() == castOther.getContactId()) || (this .getContactId() != null && castOther.getContactId() != null && this.getContactId() .equals(castOther.getContactId()))) && ((this.getFirstName() == castOther.getFirstName()) || (this .getFirstName() != null && castOther.getFirstName() != null && this .getFirstName().equals(castOther.getFirstName()))) && ((this.getMiddleName() == castOther.getMiddleName()) || (this .getMiddleName() != null && castOther.getMiddleName() != null && this .getMiddleName().equals(castOther.getMiddleName()))) && ((this.getLastName() == castOther.getLastName()) || (this .getLastName() != null && castOther.getLastName() != null && this .getLastName().equals(castOther.getLastName()))); } public int hashCode() { int result = 17; result = 37 * result + (getContactId() == null ? 0 : this.getContactId().hashCode()); result = 37 * result + (getFirstName() == null ? 0 : this.getFirstName().hashCode()); result = 37 * result + (getMiddleName() == null ? 0 : this.getMiddleName() .hashCode()); result = 37 * result + (getLastName() == null ? 0 : this.getLastName().hashCode()); return result; } }
Loyal WaterMemberMoving to Off Topic >> Software Development.
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)