-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: one-to-many problem
PostPosted: Sun Jan 23, 2011 8:25 am 
Newbie

Joined: Mon Aug 03, 2009 3:10 pm
Posts: 7
Hello, i have this error for some hours now and i don't get it anymore. It's a project with Spring 2.5 and hibernate3. I have tried with declaring a project object in the client object too.

I have 2 tables: client and project

Code:
CREATE TABLE client (clientId INT NOT NULL,
                     PRIMARY KEY (clientId)
) ENGINE=INNODB;
CREATE TABLE project (projectId INT, clientId INT,
                    INDEX par_ind (clientId),
                    FOREIGN KEY (clientId) REFERENCES client(clientId)
                      ON DELETE CASCADE
) ENGINE=INNODB;


in Java code:
Code:
public class Project implements Serializable {

   private int id;
   private String name;
   private String description;
   private Date startDate;
   private Date endDate;
   private String manager;
   private Client client;

   public Project(String name, Date startDate, Date endDate) {

      this.name = name;
      this.startDate = startDate;
      this.endDate = endDate;
   }

   public int getId() {
      return id;
   }

   public void setId(int id) {
      this.id = id;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getDescription() {
      return description;
   }

   public void setDescription(String description) {
      this.description = description;
   }

   public Date getStartDate() {
      return startDate;
   }

   public void setStartDate(Date startDate) {
      this.startDate = startDate;
   }

   public Date getEndDate() {
      return endDate;
   }

   public void setEndDate(Date endDate) {
      this.endDate = endDate;
   }

   public String getManager() {
      return manager;
   }

   public void setManager(String manager) {
      this.manager = manager;
   }
   
   public Client getClient() {
      return client;
   }

   public void setClient(Client client) {
      this.client = client;
   }

   public String toString() {
      StringBuffer buffer = new StringBuffer();
      buffer.append("Project name: " + name);
      buffer.append("Project description: " + description);
      buffer.append("Project start date: " + startDate);
      buffer.append("Project end date: " + endDate);
      return buffer.toString();
   }

   public boolean equals(Object obj) {
      if ((obj instanceof Project)
            && (((Project) obj).getName() == this.name)) {
         return true;
      }
      return false;
   }

}

Code:
public class Client implements Serializable {

   /**
    *
    */
   private static final long serialVersionUID = 1L;
   private int id;
   private String name;
   private String company;
   private String location;
   private String city;
   private String country;

   public Client() {

   }

   public Client(String name) {
      this.name = name;
   }

   public int getId() {
      return id;
   }

   public void setId(int id) {
      this.id = id;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getCompany() {
      return company;
   }

   public void setCompany(String company) {
      this.company = company;
   }

   public String getLocation() {
      return location;
   }

   public void setLocation(String location) {
      this.location = location;
   }

   public String getCity() {
      return city;
   }

   public void setCity(String city) {
      this.city = city;
   }

   public String getCountry() {
      return country;
   }

   public void setCountry(String country) {
      this.country = country;
   }
   
   public String toString() {
      StringBuffer buffer = new StringBuffer();
      buffer.append("Client name: " + name);
      buffer.append("Client company: " + company);
      buffer.append("Client location: " + location);
      buffer.append("Client city: " + city);
      buffer.append("Client country: " + country);
      return buffer.toString();
   }

   public boolean equals(Object obj) {
      if ((obj instanceof Client) && (((Client) obj).getName() == this.name)) {
         return true;
      }
      return false;
   }

}


In hibernate mapping files i have this:
Code:
<hibernate-mapping package="test.domain">
   <class name="Client" table="clients" dynamic-update="true">
      <id name="id" column="clientId" type="integer">
         <generator class="increment" />
      </id>
      <property name="name" column="name" type="string" />
      <property name="company" column="company" type="string" />
      <property name="location" column="location" type="string" />
      <property name="city" column="city" type="string" />
      <property name="country" column="country" type="string" />

   </class>
</hibernate-mapping>


and
Code:
<hibernate-mapping package="test.domain">
   <class name="Project" table="project" dynamic-update="true">
      <id name="id" column="projectId" type="integer">
         <generator class="increment" />
      </id>
      <property name="name" column="name" type="string" />
      <property name="description" column="description" type="string" />
      <property name="startDate" column="start_date" type="string" />
      <property name="endDate" column="end_date" type="string" />
      <property name="manager" column="manager" type="string" />

      <!-- a client has many projects -->
      <many-to-one name="client" column="clientId"
         class="test.domain.Client" cascade="save-update" lazy="false" />

   </class>
</hibernate-mapping>


And i receive this error:
Code:
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for description in class test.domain.Client
   at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282)
   at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:275)


Way to wrapped out into this problem and now i don't even know if this is the correct way to declare the relations between the client and the project. Do you see a mistake in the code above? Thank you very much anyway.


Top
 Profile  
 
 Post subject: Re: one-to-many problem
PostPosted: Mon Jan 24, 2011 6:51 am 
Newbie

Joined: Mon Aug 03, 2009 3:10 pm
Posts: 7
Hello, i found out that the problem was my attention, this code worked fine, but there was an error in another hbm.xml, a duplicate name Clients instead of the required one.
thx


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.