Hello,
I have a problem trying to write my RightTO object to the database.
My RightTO class looks like this:
Code:
*
* @hibernate.class table="RIGHTS"
*/
public class RightTO extends BaseTO implements Serializable{
private int id;
private int actionID,roleID;
/**
* @hibernate.id generator-class="increment"
* unsaved-value="0"
* type="integer"
* column="RIGHT_ID"
* @return
*/
public int getId() {
return id;
}
/**
* @param i
*/
public void setId(int i) {
id = i;
}
/**
* @hibernate.many-to-one column="ACTION_ID" not-null="true" class="be.sofico.kiteserver.resource.common.system.rightmanagement.ActionTO"
* @return
*/
public int getActionID() {
return actionID;
}
/**
* @hibernate.many-to-one column="USERROLE_ID" not-null="true" class="be.sofico.kiteserver.resource.common.system.usermanagement.UserRoleTO"
* @return
*/
public int getRoleID() {
return roleID;
}
/**
* @param i
*/
public void setActionID(int i) {
actionID = i;
}
/**
* @param i
*/
public void setRoleID(int i) {
roleID = i;
}
The UserRoleTO class looks like this:
Code:
*
* @hibernate.class table="USERROLE"
*/
public class UserRoleTO extends BaseTO implements Serializable{
private int roleID;
private String roleName;
/**
* @hibernate.id generator-class="increment"
* unsaved-value="0"
* type="integer"
* column="USERROLE_ID"
* @return
*/
public int getRoleID() {
return roleID;
}
/**
* @hibernate.property column="NAME"
* type="string"
* length="30"
* not-null="true"
* unique="true"
* @return String
*/
public String getRoleName() {
return roleName;
}
/**
* @param string
*/
public void setRoleName(String string) {
roleName = string;
}
/**
* @param i
*/
public void setRoleID(int i) {
roleID = i;
}
My ActionTO class looks like this:
Code:
*
* @hibernate.class table="ACTION"
*/
public class ActionTO extends BaseTO implements Serializable {
private int actionID;
private String name;
private String description;
private Set Rights;
/**
* @hibernate.id generator-class="increment"
* unsaved-value="0"
* type="integer"
* column="ACTION_ID"
* @return
*/
public int getActionID() {
return actionID;
}
/**
* @param i
*/
public void setActionID(int i) {
actionID = i;
}
/**
* @hibernate.property column="NAME"
* type="string"
* length="30"
* not-null="true"
* unique="false"
* @return String
*/
public String getName() {
return name;
}
/**
* @hibernate.property column="DESCRIPTION"
* type="string"
* length="30"
* not-null="true"
* unique="false"
* @return String
*/
public String getDescription() {
return description;
}
/**
* @param string
*/
public void setDescription(String string) {
description = string;
}
/**
* @param string
*/
public void setName(String string) {
name = string;
}
When i create my hibernate mapping, it looks like this for RightTO.hbm.xml:
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="be.sofico.kiteserver.resource.common.system.rightmanagement.RightTO"
table="RIGHTS"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="RIGHT_ID"
type="integer"
unsaved-value="0"
>
<generator class="increment">
</generator>
</id>
<many-to-one
name="actionID"
class="be.sofico.kiteserver.resource.common.system.rightmanagement.ActionTO"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="ACTION_ID"
not-null="true"
/>
<many-to-one
name="roleID"
class="be.sofico.kiteserver.resource.common.system.usermanagement.UserRoleTO"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="USERROLE_ID"
not-null="true"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-RightTO.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
The UserRoleTO.hbm.xml file looks like this:
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="be.sofico.kiteserver.resource.common.system.usermanagement.UserRoleTO"
table="USERROLE"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="roleID"
column="USERROLE_ID"
type="integer"
unsaved-value="0"
>
<generator class="increment">
</generator>
</id>
<property
name="roleName"
type="string"
update="true"
insert="true"
column="NAME"
length="30"
not-null="true"
unique="true"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-UserRoleTO.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
And the ActionTO.hbm.xml looks like this:
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="be.sofico.kiteserver.resource.common.system.rightmanagement.ActionTO"
table="ACTION"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="actionID"
column="ACTION_ID"
type="integer"
unsaved-value="0"
>
<generator class="increment">
</generator>
</id>
<property
name="name"
type="string"
update="true"
insert="true"
column="NAME"
length="30"
not-null="true"
unique="false"
/>
<property
name="description"
type="string"
update="true"
insert="true"
column="DESCRIPTION"
length="30"
not-null="true"
unique="false"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ActionTO.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Now, the tables are created correctly, but when i want to write a RightTO object to the database, i get the following MappingException Error:
Code:
net.sf.hibernate.MappingException: No persister for: java.lang.Integer
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2656)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2663)
at net.sf.hibernate.impl.SessionImpl.isUnsaved(SessionImpl.java:1064)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:1010)
at net.sf.hibernate.impl.SessionImpl.nullifyTransientReferences(SessionImpl.java:996)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:901)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:839)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:761)
at net.sf.hibernate.impl.SessionImpl.doCopy(SessionImpl.java:3966)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdateCopy(SessionImpl.java:3938)
at be.sofico.kiteserver.common.system.rightmanagement.RightDAO.setRight(RightDAO.java:75)
at test.RightDAOTest.testSetRight(RightDAOTest.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
Please help me out, i can't seem to find a solution.
Thx[/code]