Hi,
I have got a big problem, I want to use those two mapping files and create a DAOTest for it. I added the DAOTest below. When I run this test I get the getter Exception, allthough they exist. The mapping files and the java classes, both were create with JBOSS IDE Hibernate.
How do I solve this generally with the mapping files and foreign keys?
Hibernate version:3
MySQL
debug
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="clara.bo.model.User" table="user">
<id name="Uid" type="java.lang.Integer">
<column name="uid" scale="10" precision="0" not-null="true" sql-type="int" />
<generator class="assigned" />
</id>
<property name="Uname" type="java.lang.String">
<column name="uname" scale="30" precision="0" not-null="true" sql-type="varchar" />
</property>
<property name="Urealname" type="java.lang.String">
<column name="urealname" scale="30" precision="0" not-null="true" sql-type="varchar" />
</property>
<property name="Usurname" type="java.lang.String">
<column name="usurname" scale="30" precision="0" not-null="true" sql-type="varchar" />
</property>
<property name="Upassword" type="java.lang.String">
<column name="upassword" scale="30" precision="0" not-null="true" sql-type="varchar" />
</property>
<property name="Uemail" type="java.lang.String">
<column name="uemail" scale="40" precision="0" not-null="true" sql-type="varchar" />
</property>
<property name="Uurl" type="java.lang.String">
<column name="uurl" scale="50" precision="0" not-null="true" sql-type="varchar" />
</property>
<property name="Usig" type="java.lang.String">
<column name="usig" scale="200" precision="0" not-null="true" sql-type="varchar" />
</property>
<property name="Uadmin" type="java.lang.Byte">
<column name="uadmin" scale="1" precision="0" not-null="false" sql-type="tinyint" />
</property>
<property name="Uaarea" type="java.lang.Byte">
<column name="uaarea" scale="1" precision="0" not-null="false" sql-type="tinyint" />
</property>
<property name="Udeflang" type="java.lang.String">
<column name="udeflang" scale="20" precision="0" not-null="false" sql-type="varchar" />
</property>
<set name="SetOfTeam">
<key>
<column name="tid" scale="10" precision="0" not-null="false" unique="true" />
</key>
<one-to-many class="clara.bo.model.Team" />
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="clara.bo.model.Team" table="team">
<composite-id name="id" class="clara.bo.model.TeamId">
<key-many-to-one name="User" class="clara.bo.model.User">
<column name="tid" scale="10" precision="0" not-null="false" unique="true" />
</key-many-to-one>
<key-property name="Tblog" type="java.lang.Integer">
<column name="tblog" scale="10" precision="0" not-null="false" sql-type="int" />
</key-property>
<key-property name="Tadmin" type="java.lang.Byte">
<column name="tadmin" scale="1" precision="0" not-null="false" sql-type="tinyint" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
Code:
* 27.04.2005
* 11:30:50
* johannes.hiemer
* UserDAOTest.java
*/
package clara.dao.test;
import junit.textui.TestRunner;
import org.apache.log4j.Logger;
import clara.bo.dao.IUserDAO;
import clara.bo.model.User;
/**
* @author johannes.hiemer
*
* Clara
*/
public class UserDAOTest extends BaseDAOTestCase {
private User user;
private IUserDAO dao;
/**
*
*/
protected void setUp() throws Exception {
log = Logger.getLogger(UserDAOTest.class.getName());
dao = (IUserDAO) ctx.getBean("userDAO");
}
protected void tearDown() throws Exception {
dao = null;
}
public static void main(String [] arg) {
TestRunner.run(UserDAOTest.class);
}
public void testSaveUser() throws Exception {
user = new User();
user.setUurl("http://www.planet-tutorials.de");
user.setUsurname("Valentin");
user.setUsig("Kämpfen");
user.setUrealname("Johannes");
user.setUpassword("valentin");
user.setUname("Hiemer");
user.setUemail("johannes.hiemer@itecon.de");
user.setUdeflang("de_DE");
user.setUadmin((byte) 1);
user.setUaarea((byte) 0);
user.setUid(new Integer(0));
dao.saveUser(user);
assertTrue("primary key assigned", user.getUid() != null);
log.info(user);
assertTrue(user.getUname() != null);
}
public void testAddAndRemoveUser() throws Exception {
user = new User();
user.setUurl("http://www.planet-tutorials.des");
user.setUsurname("Valentins");
user.setUsig("Kämpfens");
user.setUrealname("Johanness");
user.setUpassword("valentin");
user.setUname("Hiemers");
user.setUemail("johannes.hiemer@itecon.des");
user.setUdeflang("de_DEs");
user.setUadmin((byte) 0);
user.setUaarea((byte) 1);
user.setUid(new Integer(1));
dao.saveUser(user);
assertTrue(user.getUid() != null);
assertTrue(user.getUname().equals("Hiemers"));
if(log.isDebugEnabled()) {
log.debug("removing temporary created user...");
}
dao.removeUser(user.getUid());
assertNull(dao.getUser(user.getUid()));
}
}
org.hibernate.PropertyNotFoundException: Could not find a getter for User in class clara.bo.model.TeamId
Thank for any help, comments, or criticisim.
Regards Valentin-