Sorry to reopen this for discussion. This is very important to the migration
of my application. 

It seems like @prepersist works just fine in a JPA project
I took my entity POJO Catalog to a separate JPA Hibernate enabled project
with these dependencies 
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate</artifactId>
      <version>3.2.1.ga</version>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-annotations</artifactId>
      <version>3.2.0.ga</version>
    </dependency>
and then wrote this test -

public class CatalogEntityTest extends TestCase {
    private EntityManager em;
    private EntityManagerFactory emf;
    private Catalog catalog;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        emf = Persistence.createEntityManagerFactory("cast-mysql");
        em = emf.createEntityManager();
        catalog = new Catalog();
        catalog.setCatalogName("Sony Rewards");
        //catalog.setActive("Y");
    }

    @Override
    protected void tearDown() throws Exception {
        em.close();
        emf.close();
        super.tearDown();
    }

    public void testPersist() {
        // no primary key
        assertNull(catalog.getId());
        em.getTransaction().begin();
        em.persist(catalog);
        em.getTransaction().commit();

        assertNotNull( catalog.getId());
    }

}


This test ran fine and inserted a record into my catalog table.  

Basically all I'm trying to achieve is set defaults for not null columns. Of
course I could do this with triggers in my target database Oracle. But I
would rather stick with mysql for development.


It seems like a similar error was reported at
http://lists.jboss.org/pipermail/hibernate-issues/2007-February/003510.html

Thanks
Franco


-- 
View this message in context: 
http://www.nabble.com/Setting-Entity-defaults-with-%40PrePersist-tf3928714s2369.html#a11176436
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