Sorry, here it is

I am using appfuse 2 with Hibernate implementation. 
I have a table with this definition 
  
  CREATE TABLE /*!32312 IF NOT EXISTS*/ `catalog` 
  ( `id` bigint(20) NOT NULL auto_increment, 
     `catalog_name` varchar(100) NOT NULL,
        `active` varchar(1) NOT NULL, 
        `date_created` datetime default NULL, 
        PRIMARY  KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 
        
I would like to set defaults for active and date_created columns. 
So in my Catalog POJO, I declared 
                @PrePersist
                public void setDefaults() {
                        
                        //All new catalog records should be active.
                        if (getActive() == null )  {
                                setActive("Y");
                        }
                        
                        if (getDateCreated() == null) {
                                setDateCreated(new Date());
                        }
                }       


When I attempt to save, I get this error 
Caused by: org.springframework.dao.DataIntegrityViolationException: not-null
property references a null or transient value:
com.sonycard.cast.model.Catalog.acti
ve; nested exception is org.hibernate.PropertyValueException: not-null
property references a null or transient value:
com.sonycard.cast.model.Catalog.active
        at
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:628)
        at
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
        at
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:377)
        at
org.springframework.orm.hibernate3.HibernateTemplate.merge(HibernateTemplate.java:762)
        at
org.appfuse.dao.hibernate.GenericDaoHibernate.save(GenericDaoHibernate.java:64)
        at
org.appfuse.service.impl.GenericManagerImpl.save(GenericManagerImpl.java:64)


I then moved my @PrePersist method into a model listener class and annotated
my POJO with it. 

@EntityListeners({com.sonycard.cast.model.listener.CatalogModelListener.class}) 

I still get the same error. Anyone know how to set defaults for entity
fields? 

Would one solution be to write a custom manager (like PersonManager in the
tutorial) and override the save() method?.  

Thanks 
Franco

 
-- 
View this message in context: 
http://www.nabble.com/Setting-Entity-defaults-with-%40PrePersist-tf3928714s2369.html#a11144501
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to