emmanuel wrote:
Please read the red header and particulary the stacktrace and code (your POJO one)
Sorry, my mistake. Forgot to add the other important elements...here are all of them:
1. Mapping for Study:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="uk.org.mygrid.mir.infomodel.EScienceProcess.Study" table="study">
<id name="LSID" type="java.lang.String" column="study_id" length="80">
<generator class="assigned"/>
</id>
<property name="name" type="java.lang.String" column="name" length="80"/>
<property name="startTime" type="java.sql.Date" column="startTime" length="10"/>
<property name="endTime" type="java.sql.Date" column="endTime" length="10"/>
<property name="status" type="java.lang.String" column="status" length="10"/>
<property name="description" type="java.lang.String" column="description" length="100"/>
<!-- associations -->
<!-- bi-directional one-to-many association to Experimentinstance -->
<set name="experimentinstances" lazy="true" inverse="true">
<key>
<column name="parent_study_id"/>
</key>
<one-to-many class="uk.org.mygrid.mir.infomodel.EScienceProcess.ExperimentInstance"/>
</set>
<!-- bi-directional many-to-one association to Labbookview -->
<many-to-one name="labbookview" class="uk.org.mygrid.mir.infomodel.EScienceProcess.LabBookView" not-null="true">
<column name="associated_labbook_id"/>
</many-to-one>
<!-- bi-directional many-to-one association to Programme -->
<many-to-one name="programme" class="uk.org.mygrid.mir.infomodel.EScienceProcess.Programme" not-null="true">
<column name="related_programme_id"/>
</many-to-one>
</class>
</hibernate-mapping>
2. Mapping for Person:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.Person" table="person">
<id name="LSID" type="java.lang.String" column="person_id" length="80">
<generator class="assigned"/>
</id>
<property name="firstName" type="java.lang.String" column="fName" not-null="true" length="20"/>
<property name="lastName" type="java.lang.String" column="lName" not-null="true" length="30"/>
<property name="email" type="java.lang.String" column="email" not-null="true" length="80"/>
<property name="x509DN" type="java.lang.String" column="x509dn" not-null="true" length="50"/>
<!-- associations -->
<!-- bi-directional many-to-many association to Address -->
<set name="addresses" table="address_persons">
<key>
<column name="person_id" length="80"/>
</key>
<many-to-many column="address_id" class="uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.Address"/>
</set>
<!-- bi-directional many-to-many association to StudyParticipationEpisode (association class) -->
<set name="studyparticipations" table="studyparticipationepisode">
<key>
<column name="person_id" length="80"/>
</key>
<composite-element class="uk.org.mygrid.mir.infomodel.EScienceProcess.StudyParticipationEpisode">
<property name="startDate" type="java.sql.Date"/>
<property name="endDate" type="java.sql.Date"/>
<property name="role" type="java.lang.String" length="20"/>
<property name="description" type="java.lang.String" length="30"/>
<many-to-one name="study" class="uk.org.mygrid.mir.infomodel.EScienceProcess.Study"/>
</composite-element>
</set>
<!-- bi-directional one-to-many association to Affiliation -->
<set name="affiliations" lazy="true" inverse="true">
<key>
<column name="affiliated_person_id"/>
</key>
<one-to-many class="uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.Affiliation"/>
</set>
<!-- bi-directional one-to-many association to LabBook (one person can have multiple LabBooks) -->
<set name="labBooks" lazy="true" inverse="true">
<key>
<column name="person_id"/>
</key>
<one-to-many class="uk.org.mygrid.mir.infomodel.EScienceProcess.LabBookView"/>
</set>
</class>
</hibernate-mapping>
3. POJO of Study:
Code:
public class Study extends Resource implements Serializable {
private String name;
private Date startTime;
private Date endTime;
private String status;
private String description;
private LabBookView labbookview;
private Programme programme;
private Set experimentinstances;
public String getDescription() {
return description;
}
public Date getEndTime() {
return endTime;
}
public Set getExperimentinstances() {
return experimentinstances;
}
public LabBookView getLabbookview() {
return labbookview;
}
public String getName() {
return name;
}
public Programme getProgramme() {
return programme;
}
public Date getStartTime() {
return startTime;
}
public String getStatus() {
return status;
}
public void setDescription(String string) {
description = string;
}
public void setEndTime(Date date) {
endTime = date;
}
public void setExperimentinstances(Set set) {
experimentinstances = set;
}
public void setLabbookview(LabBookView view) {
labbookview = view;
}
public void setName(String string) {
name = string;
}
public void setProgramme(Programme programme) {
this.programme = programme;
}
public void setStartTime(Date date) {
startTime = date;
}
public void setStatus(String string) {
status = string;
}
}
4. POJO of Person:
Code:
public class Person extends Resource implements Serializable {
private String x509DN;
private String firstName;
private String lastName;
private String email;
private Set addresses;
private Set affiliations;
private Set labBooks;
private Set studyparticipations;
public Set getAddresses() {
return addresses;
}
public Set getAffiliations() {
return affiliations;
}
public String getEmail() {
return email;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getX509DN() {
return x509DN;
}
public void setAddresses(Set set) {
addresses = set;
}
public void setAffiliations(Set set) {
affiliations = set;
}
public void setEmail(String string) {
email = string;
}
public void setFirstName(String string) {
firstName = string;
}
public void setLastName(String string) {
lastName = string;
}
public void setX509DN(String string) {
x509DN = string;
}
public Set getLabBooks() {
return labBooks;
}
public void setLabBooks(Set set) {
labBooks = set;
}
public Set getStudyparticipations() {
return studyparticipations;
}
public void setStudyparticipations(Set set) {
studyparticipations = set;
}
}
5. POJO of StudyParticipationEpisode:
Code:
public class StudyParticipationEpisode implements Serializable {
private Date startDate;
private Date endDate;
private String role;
private String description;
private Study study;
public String getDescription() {
return description;
}
public Date getEndDate() {
return endDate;
}
public String getRole() {
return role;
}
public Date getStartDate() {
return startDate;
}
public void setDescription(String string) {
description = string;
}
public void setEndDate(Date date) {
endDate = date;
}
public void setRole(String string) {
role = string;
}
public void setStartDate(Date date) {
startDate = date;
}
public Study getStudy() {
return study;
}
public void setStudy(Study study) {
this.study = study;
}
}
6. StackTrace:
Code:
test:
[javac] Compiling 7 source files to F:\Work\working\mygrid\MIR\build
[echo] remember to place your JDBC driver in the lib directory
[copy] Copying 1 file to F:\Work\working\mygrid\MIR\build\uk\org\mygrid\mir\test
[java] Creating configuration...
[java] - Hibernate 2.1.2
[java] - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.gjt.mm.mysql.Driver, hibernate.cglib.use_re
flection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cache.use_query_cache=true, hibernate
.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0,
hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=arijitm, hibernate.c
onnection.url=jdbc:mysql://localhost:3306/mir, hibernate.connection.password=password, hibernate.connection.pool_size=1}
[java] - using java.io streams to persist binary types
[java] - using CGLIB reflection optimizer
[java] - Mapping resource: uk/org/mygrid/mir/infomodel/PeopleAndOrganizations/Person.hbm.xml
[java] - Mapping class: uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.Person -> person
[java] - Mapping collection: uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.Person.addresses -> address_persons
[java] - Mapping collection: uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.Person.studyparticipations -> studyparticipationepisode
[java] - Mapping resource: uk/org/mygrid/mir/infomodel/PeopleAndOrganizations/Address.hbm.xml
[java] - Mapping class: uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.Address -> address
[java] - Mapping collection: uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.Address.addressee -> address_persons
[java] - Mapping resource: uk/org/mygrid/mir/infomodel/PeopleAndOrganizations/OrganizationalStructure.hbm.xml
[java] - Mapping class: uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.OrganizationalStructure -> organizationalstructure
[java] - Mapping resource: uk/org/mygrid/mir/infomodel/PeopleAndOrganizations/OrganizationalUnit.hbm.xml
[java] - Mapping class: uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.OrganizationalUnit -> organizationalunits
[java] - Mapping resource: uk/org/mygrid/mir/infomodel/PeopleAndOrganizations/Affiliation.hbm.xml
[java] - Mapping class: uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.Affiliation -> affiliation
[java] - Mapping resource: uk/org/mygrid/mir/infomodel/PeopleAndOrganizations/AffiliationEpisode.hbm.xml
[java] - Mapping class: uk.org.mygrid.mir.infomodel.PeopleAndOrganizations.AffiliationEpisode -> affiliationepisode
[java] - processing one-to-many association mappings
[java] net.sf.hibernate.PropertyNotFoundException: Could not find a setter for property startDate in class uk.org.mygrid.mir.infomodel.EScienceProcess.StudyParticipationEpisode
[java] at net.sf.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:131)
[java] at net.sf.hibernate.mapping.Property.getSetter(Property.java:182)
[java] at net.sf.hibernate.cfg.Binder.bindComponent(Binder.java:881)
[java] at net.sf.hibernate.cfg.Binder.bindCollectionSecondPass(Binder.java:1191)
[java] at net.sf.hibernate.cfg.Binder$CollectionSecondPass.secondPass(Binder.java:1352)
[java] at net.sf.hibernate.cfg.Binder$SecondPass.doSecondPass(Binder.java:1328)
[java] at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:600)
[java] at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:743)
[java] at uk.org.mygrid.mir.test.HibernateTest.main(HibernateTest.java:267)
[java] java.lang.RuntimeException: couldn't get connection
[java] at uk.org.mygrid.mir.test.HibernateTest.main(HibernateTest.java:274)
[java] Exception in thread "main"
It has something to do with the many-to-many mapping with attributes between Person and Study, because once I remove this (and remove the associated POJOs), the rest works.
A related question: If I use hbm2java to generate the POJOs from my mapping files, it generates an extra POJO called StudyParticipation - I can't figure out where it is coming from...
Hoping for a solution...
Cheers
Arijit