I now have a simple example and it's starting to work, but still has problems. (See below) I have two classes ParentClass and ChildClass. ParentClass uses a java.util.map to hold all the children.
ParentClass
Code:
public class ParentClass {
private Long id;
private java.util.Map children = new java.util.HashMap();
private String text = "";
public ParentClass() {super();}
public Long getId() {return id;}
private void setId(Long id) {this.id = id;}
public Map getChildren() {return children;}
public void setChildren(Map _children) {children = _children;}
public String getText() {return text;}
public void setText(String _text) {text = _text;}
public void addChild(ChildClass _child){children.put(_child.getChildKey(), _child.getText());}
ChildClassCode:
public class ChildClass {
private Long id;
private String childKey = "";
private String text = "";
public ChildClass() {super();}
public Long getId() {return id;}
private void setId(Long id) {this.id = id;}
public String getText() {return text;}
public void setText(String _text) { text = _text;}
public String getChildKey() {return childKey;}
public void setChildKey(String _childKey) {childKey = _childKey;}
Database schemaCode:
DROP TABLE IF EXISTS PARENT;
CREATE TABLE PARENT (
ParentId int (11) unsigned auto_increment,
FKColumnInParentTable int (11) unsigned,
ParentText varchar(255) default '',
PRIMARY KEY (ParentId)
) TYPE=MyISAM;
DROP TABLE IF EXISTS CHILD;
CREATE TABLE CHILD (
ChildId int (11) unsigned auto_increment,
ChildKey varchar(20) default '',
ChildText varchar(255) default '',
PRIMARY KEY (ChildId)
) TYPE=MyISAM;
ParentClass.hbm.xmlCode:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="sample">
<class name="ParentClass" table="PARENT" lazy="true">
<id name="id" column="ParentId">
<generator class="native"/>
</id>
<property name="text"
column="ParentText"/>
<map name="children" lazy="true"
cascade="save-update,lock">
<key column="FKColumnInParentTable"/>
<map-key column="childKey" type="string"/>
<one-to-many class="ChildClass"/>
</map>
</class>
</hibernate-mapping>
ChildClass.hbm.xmlCode:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="sample">
<class name="ChildClass" table = "CHILD">
<id name="id" column="ChildId">
<generator class="native"/>
</id>
<property
name="childKey"
column="ChildKey"/>
<property
name="text"
column="ChildText"/>
</class>
</hibernate-mapping>
The First Error
Quote:
12:11:10,491 DEBUG ConnectionManager:358 - opening JDBC connection
12:11:10,492 DEBUG JDBCExceptionReporter:63 - Cannot open connection [???]
java.sql.SQLException: com.mchange.v2.c3p0.PoolBackedDataSource@92b39f [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@1075c5 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1075c5, idleConnectionTestPeriod -> 3003, initialPoolSize -> 5, maxIdleTime -> 300, maxPoolSize -> 20, maxStatements -> 31, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@da801b [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> da801b, jdbcUrl -> jdbc:mysql:///helloworld, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ], factoryClassLocation -> null, identityToken -> 92b39f, numHelperThreads -> 3 ] has been closed() -- you can no longer use it.
at com.mchange.v2.c3p0.PoolBackedDataSource.assertCpds(PoolBackedDataSource.java:234)
The Second Error -- The most important one to solveQuote:
ERROR BasicPropertyAccessor:167 - IllegalArgumentException in class: sample.ChildClass, getter method of property: id