Wie in der Hibernate Anleitung(3.2.0) im Kapitel 7.4.1 versuche ich eine bidirektionale One-to-Many Assoziation abzubilden. Wenn ich die Datensätze versuche zu laden, egal ob SQL oder HQL Query erhalte ich eine Exception.
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of dataObjects.Command.refCheckCommandHost
Hibernate version:
hibernate-3.2.1.ga.zip
Java Klassen
Code:
public class Host {
private String OID = "";
private Command hostCheckCommand = null;
public Command getHostCheckCommand() {
return hostCheckCommand;
}
public String getOID() {
return OID;
}
public void setHostCheckCommand(Command hostCheckCommand) {
this.hostCheckCommand = hostCheckCommand;
}
public void setOID(String oid) {
OID = oid;
}
}
public class Command {
private String OID = "";
private TreeSet<Host> refCheckCommandHost = null;
public String getOID() {
return OID;
}
public TreeSet<Host> getRefCheckCommandHost() {
return refCheckCommandHost;
}
public void setOID(String oid) {
OID = oid;
}
public void setRefCheckCommandHost(TreeSet<Host> refCheckCommandHost) {
this.refCheckCommandHost = refCheckCommandHost;
}
}
Mapping documents:Code:
<class name="Command" table="command">
<id name="OID">
<generator class="uuid" />
</id>
<set name="refCheckCommandHost " inverse="true">
<key column="hostcheckcommand" />
<one-to-many class="Host" />
</set>
</class>
Code:
<class name="Host" table="host">
<id name="OID">
<generator class="uuid" />
</id>
<many-to-one name="hostCheckCommand" column="hostcheckcommand" />
</class>
DB Tabellen:Code:
CREATE TABLE host (
OID varchar(64) UNIQUE PRIMARY KEY,
hostcheckcommand varchar(64) REFERENCES command (OID)
);
CREATE TABLE command (
OID varchar(64) UNIQUE PRIMARY KEY
);
Code between sessionFactory.openSession() and session.close():Code:
java.util.List x = session.createQuery("from TimePeriod").list();
Full stack trace of any exception that occurs:Code:
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of dataObjects.Command.refCheckCommandHost
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:200)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3514)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at dataObjects.ServerSet.loadServerSetFromDB(ServerSet.java:57)
at test.testSimpleDBConnection.main(testSimpleDBConnection.java:19)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
... 17 more
17:21:17,802 ERROR BasicPropertyAccessor:94 - IllegalArgumentException in class: dataObjects.Command, setter method of property: refCheckCommandHost
17:21:17,802 ERROR BasicPropertyAccessor:98 - expected type: java.util.TreeSet, actual value: org.hibernate.collection.PersistentSet
Name and version of the database you are using:PostgreSQL 8.2
The generated SQL (show_sql=true):Code:
17:21:17,652 DEBUG SQL:393 - select command0_.OID as OID0_, command0_.commandName as commandN2_0_, command0_.commandLine as commandL3_0_, command0_.beforedefinition as beforede4_0_, command0_.afterdefinition as afterdef5_0_, command0_.shellcommand as shellcom6_0_ from command command0_
Hibernate: select command0_.OID as OID0_, command0_.commandName as commandN2_0_, command0_.commandLine as commandL3_0_, command0_.beforedefinition as beforede4_0_, command0_.afterdefinition as afterdef5_0_, command0_.shellcommand as shellcom6_0_ from command command0_