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
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:
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 Stri开发者_高级运维ng 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;
}
}
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:
<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
<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:
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.
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. I was looking in the wrong place, it was my mistake. Thank you.
精彩评论