I know I've done a million times, but this many-to-many isn't saving. I'm using hibernate 3.3.1ga with spring 3.0.0m4.
Code:
@Test
public void save() {
Job job = new Job();
...
job.addCategory( categoryDao.find( 1 ) );
jobDao.save( job );
clear();
assertFalse( job.isTransient() );
jdbcMap = simpleJdbcTemplate.queryForMap( "select * from job where job_id = ?", job.getId() );
... // test stuff
// Spring FAILS here - it cannot find 1 row.
jdbcMap = simpleJdbcTemplate.queryForMap( "select * from job_to_category where job_id = ?", job.getId() );
assertEquals( 1, jdbcMap.get( "CATEGORY_ID" ) );
}
Here is the mapping:
Code:
<hibernate-mapping default-access="field" auto-import="true" default-lazy="true" default-cascade="all-delete-orphan">
<class name="myproject.domain.job.Job" table="job">
<id name="id" column="job_id" type="long">
<generator class="native"/>
</id>
<property name="positionName" column="position_name"/>
<property name="description" type="text"/>
<property name="excerpt" type="text"/>
<property name="googleMapUrl" column="google_map_url"/>
<property name="expiryDate" column="expiry_date"
type="org.joda.time.contrib.hibernate.PersistentLocalDate" />
<property name="views"/>
<bag name="categories" table="job_to_category">
<key column="job_id" />
<many-to-many class="myproject.domain.Category" column="category_id" />
</bag>
</class>
<class name="myproject.domain.Category" table="category">
<id name="id" column="category_id" type="long">
<generator class="native"/>
</id>
<property name="name" column="name"/>
<many-to-one name="parent" class="myproject.domain.Category"
column="parent_id"/>
<set name="children" inverse="true">
<key column="category_id"/>
<one-to-many class="myproject.domain.Category"/>
</set>
</class>
</hibernate-mapping>
I checked the sql output and it appears hibernate is generating an insert on job or category (if it was new)... but it's not inserting any rows into the job_to_category table.
I dunno why this isn't working. I've tried inverse="true" and "false". I'm stumped. And maybe I've been programming for long. Almost 10 hours now :/