i know this stuff is documented but i'm still having a few conceptual problems i think.
i have a table visitor with a column called role_type_id whose values belong to a table called role_type and have a foreign key constraint. i realize this is really just an object reference in the OO side of things.
i don't ever expect to work with a RoleType in my application since they are static so the relationship is not bi-directional.
i'm definitely doing something wrong when i save since i get:
javax.ejb.EJBException: nested exception is: net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.usg.domain.RoleType
my client code looks something like this and in this case i'm assuming that the column role_type_id in the parent table would become null.
Code:
Visitor visitor = new Visitor();
RoleType roleType = new RoleType();
...
visitor.setRoleType(roleType);
..
// saving:
session = SessionHelper.getSession();
session.saveOrUpdate(visitor);
session.flush();
session.close();
anyway here's my 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="com.usg.domain.Visitor"
table="VISITOR"
>
<id
name="visitorId"
type="java.lang.Integer"
column="VISITOR_ID"
>
<generator class="sequence">
<param name="sequence">visitor_id</param>
</generator>
</id>
<!-- associations -->
<!-- uni-directional many-to-one association to RoleType -->
<many-to-one
name="roleType"
class="com.usg.domain.RoleType"
>
<column name="ROLE_ID" />
</many-to-one>
</class>
</hibernate-mapping>
RoleType:
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="com.usg.domain.RoleType"
table="ROLE_TYPE"
>
<id
name="roleId"
type="java.lang.Integer"
column="ROLE_ID"
>
<generator class="sequence">
<param name="sequence">role_type_id</param>
</generator>
</id>
<property
name="description"
type="java.lang.String"
column="DESCRIPTION"
not-null="true"
length="50"
/>
<!-- associations -->
</class>
</hibernate-mapping>