-->
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: many to many relation
PostPosted: Mon Dec 22, 2003 2:58 pm 
Newbie

Joined: Mon Dec 22, 2003 2:25 pm
Posts: 2
Hi

I am working on tomcat 4.1.28 struts 1.2B2 and Hibernate 1.2.5 and mySQL

I have a many to many relationship betowin author and document
and i use the table writes in database.

author <------------- writes ----------------> book

the BOs are:

package gr.tera.alternative.bo;

import java.io.Serializable;

public class BaseBO implements Serializable{
protected long id;
protected String name;

public BaseBO() {
name = "";
}

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

public long getId() { return id; }
public String getName() { return name; }
}



package gr.tera.alternative.bo;
import java.util.List;
import java.util.ArrayList;

public class Author extends BaseBO{
private String dates;
private String review;
private String email;
private String url;
private List documents;

public Author() {
super();
dates = "";
review = "";
}

public void setDates(String dates) { this.dates = dates; }
public void setEmail(String email) { this.email = email; }
public void setUrl(String url) { this.url = url; }
public void setReview(String review) { this.review = review; }

public String getDates() { return this.dates; }
public String getReview() { return this.review;}
public String getEmail() { return this.email;}
public String getUrl() { return this.url;}


public void setDocuments(List documents) {
this.documents = documents;
}

public List getDocuments() {
return documents;
}
}


package gr.tera.alternative.bo;
import java.util.Collection;

public class Document extends BaseBO {
private int year;
private Category category;
private Kind kind;
private Collection authors;
private Collection awardEvents;
private Collection publications;

public Document() {
super();
}

public void setYear(int year) { this.year = year; }
public void setCategory(Category category) { this.category = category; }
public void setKind(Kind kind) { this.kind = kind; }
public void setAuthors(Collection authors) { this.authors = authors; }
public void setAwardEvents(Collection awardEvents) { this.awardEvents = awardEvents; }
public void setPublications(Collection publications) { this.publications = publications; }

public int getYear() { return this.year; }
public Category getCategory() { return this.category; }
public Kind getKind() { return this.kind; }
public Collection getAuthors() { return this.authors; }
public Collection getAwardEvents() { return this.awardEvents; }
public Collection getPublications() { return this.publications; }

}

and the mapping files are:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="gr.tera.alternative.bo.Author" table="Author" >

<id name="id" column="AuthorID" type="long" >
<generator class="increment"/>
</id>
<property name="name" column="AuthorName" />

<set name="documents" table="Writes" cascade="all">
<key>
<column name="AuthorID" />
</key>
<many-to-many class="gr.tera.alternative.bo.Document">
<column name="DocumentID" />
</many-to-many>
</set>

</class>

</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="gr.tera.alternative.bo.Document" table="Document" lazy="true">

<id name="id" column="DocumentID" type="long" unsaved-value="null" >
<generator class="increment"/>
</id>
<property name="name" column="DocumentTitle" />
<property name="year" column="DocumentYear" type="long" />

<many-to-one
name="Category"
column="DocumentCategoryID"
not-null="true" />

<many-to-one
name="Kind"
column="DocumentKindID"
not-null="true" />

</class>

</hibernate-mapping>


When i am running the programm i am getting the followin error in tomcat's log

2003-12-22 20:52:34 action: net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB setter of gr.tera.alternative.bo.Author.?

and in the tomcat console it displayed only the query hibernate produce and no error (i have made one to many relationships and works fine)

Thanx


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 23, 2003 12:05 pm 
Newbie

Joined: Mon Dec 22, 2003 2:25 pm
Posts: 2
OK!

The problem it was not at mapping but an integer field at database was null


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.