Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0.5
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class
name="org.borneo.model.Posting.CategorizedType"
table="CATEGORIZED_TYPE"
lazy="false"
>
<id
name="id"
column="CATEGORIZED_TYPE_ID"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="increment">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-CategorizedType.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<version
name="version"
column="version"
type="java.lang.Integer"
/>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="NAME"
length="50"
unique-key="UNIQUE_CATEGORIZED_TYPE_NAME_AT_LEVEL"
not-null="false"
/>
</property>
<many-to-one
name="parentCategorizedType"
class="org.borneo.model.Posting.CategorizedType"
cascade="none"
outer-join="false"
update="true"
insert="true"
foreign-key="FK1_PARENT_CATEGORIZED_TYPE_ID"
>
<column
name="PARENT_CATEGORIZED_TYPE_ID"
unique-key="UNIQUE_CATEGORIZED_TYPE_NAME_AT_LEVEL"
not-null="false"
/>
</many-to-one>
<set
name="childCategorizedType"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
batch-size="10"
>
<key
>
<column
name="PARENT_CATEGORIZED_TYPE_ID"
/>
</key>
<one-to-many
class="org.borneo.model.Posting.CategorizedType"
/>
</set>
<property
name="created"
type="java.util.Date"
update="false"
insert="true"
column="CREATED"
not-null="true"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-CategorizedType.xml
containing the additional properties and place it in your merge dir.
-->
</class>
<query name="CategorizedTypeIdByName"><![CDATA[
from CategorizedType catype where catype.name = ?
]]></query>
</hibernate-mapping>
===========================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class
name="org.borneo.model.Posting.PostingIdentification"
table="PostingIdentification"
>
<cache usage="transactional" />
<id
name="id"
type="java.lang.Long"
unsaved-value="none"
>
<column
name="ID"
/>
<generator class="assigned">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-PostingIdentification.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<discriminator
column="discriminator"
/>
<version
name="version"
column="version"
type="java.lang.Integer"
/>
<set
name="categorizedItems"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
foreign-key="FK2_CATEGORIZED_POST_ID"
>
<column
name="POST_ID"
length="16"
not-null="true"
/>
</key>
<one-to-many
class="org.borneo.model.Posting.CategorizedItem"
/>
</set>
<many-to-one
name="status"
class="org.borneo.model.Status"
cascade="save-update"
outer-join="auto"
update="true"
insert="true"
column="FK_STATUS_ID"
/>
<many-to-one
name="duration"
class="org.borneo.model.Posting.CategorizedType"
cascade="all"
outer-join="auto"
update="true"
insert="true"
column="duration"
not-null="true"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PostingIdentification.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="org.borneo.model.Posting.ResidentialProperties"
>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ResidentialProperties.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
public void savePostingIdentification(PostingIdentification pid){
getHibernateTemplate().saveOrUpdate(pid);
}
Name and version of the database you are using:
MySql 4.1.12
Hi guys,
I got a real freak problem here. When I saved the PostingIdentification, the CategorizedType table automatically create 1 more row, which is NULL for
NAME and
PARENT_CATEGORIZED_TYPE_ID and a new incremental value for
CATEGORIZED_TYPE_ID. This is strange as I never want to insert a new row into CategorizedType table.
Pls help, Thanks in adv !
regards,
Mark