I've been just playing around with Hibernate and the ddl creation. I've come across a problem that makes absolutely no sense.
I just insert an object into the database. Here is the test.
Code:
@Test
public void testPostNewJob() {
setCurrentUser( new EmployerUser() );
Job job = new Job();
job.setPositionName( "name" );
job.setDescription( "description" );
job.setExcerpt( "exerpt" );
job.setGoogleMapUrl( "url" );
job.setExpiryDate( new LocalDate() );
jobManager.postNewJob( job );
job = jobDao.find( job.getId() );
assertFalse( job.isTransient() );
assertEquals( "name", job.getPositionName() );
assertEquals( "description", job.getDescription() );
assertEquals( "exerpt", job.getExcerpt() );
assertEquals( "url", job.getGoogleMapUrl() );
assertNotNull( job.getExpiryDate() );
}
Here is the mapping file:
Code:
<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="views"/>
</class>
Strangely, the above Java code PASSES. Can you believe that? It should totally fail. I want it to fail... but it passes?
Here's the job Manager code:
Code:
@PreAuthorize( "hasRole( 'ROLE_EMPLOYER' )" )
public void postNewJob( Job job ) {
jobDao.save( job );
}
Here is .save:
Code:
public void save( T object ) {
getHibernateTemplate().saveOrUpdate( object );
}
Help ;)