This message came though all jumbled together. Can you resend it in plain-text?

Matt

On 6/15/07, Franco <[EMAIL PROTECTED]> wrote:
 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(catalog) { //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.active; 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 and annotated my
POJO with
@EntityListeners({com.sonycard.cast.model.listener.CatalogModelListener.class})
I still get the same error. Anyone know how to set defaults for entity
fields? Thanks Franco
________________________________
 View this message in context: Setting Entity defaults with @PrePersist
 Sent from the AppFuse - User mailing list archive at Nabble.com.



--
http://raibledesigns.com

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

Reply via email to