-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: VERY weird - Hibernate persisting all fields when shouldnt
PostPosted: Thu Sep 17, 2009 7:17 pm 
Regular
Regular

Joined: Tue May 12, 2009 6:08 am
Posts: 92
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 ;)


Last edited by mystic on Thu Sep 17, 2009 9:05 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Odd problem where hibernate... VERY weird.
PostPosted: Thu Sep 17, 2009 7:22 pm 
Regular
Regular

Joined: Tue May 12, 2009 6:08 am
Posts: 92
this is the .find as well:

Code:
   public T find( long id ) {
      return getHibernateTemplate().get( type, id );
   }


Top
 Profile  
 
 Post subject: Re: Odd problem where hibernate... VERY weird.
PostPosted: Thu Sep 17, 2009 9:03 pm 
Regular
Regular

Joined: Tue May 12, 2009 6:08 am
Posts: 92
Is Hibernate or spring making these columns "on demand" or something?

If I comment out ANY of the fields in the hibernate mapping file... dbunit complains. So, that means Hibernate hasn't execute any of the DDL code yet when db unit tries to insert some rows before the test begins.

However, can/is Hibernate adding column definitions transparently? Is this some sort of new feature that I am aware of? That's the only explanation.

It's just that this test SHOULD NOT pass. It's driving me nuts.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.