users@glassfish.java.net

TLE vs Hibernate

From: Jason Lee <lee_at_iecokc.com>
Date: Thu, 15 Mar 2007 17:18:19 -0500

In all of our apps, we are currently using Hibernate as the JPA provider
due to what we (read as, I) understood to be a bug in TLE with regard to
SequenceGenerators and PostgreSQL. I'd really like to use TLE, as I'm
not a big fan of the extra configuration step in setting up our
applications, nor am I, as our de facto GlassFish admin, a big fan of
the extra installation step of adding the Hibernate jars to the server.
Those are two points of failure I'd like to avoid. To that end, I
started testing an app of mine using TLE and hit a snag. Here's part of
my entity POJO:
 
@Entity
@Table(name = "engineers")
@SequenceGenerator(name = "ENGINEERS_SEQ", allocationSize = 1,
sequenceName = "engineers_seq")
public class Engineer implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"ENGINEERS_SEQ")
    protected Integer id;

With Hibernate, when I would create a new Engineer object, i could just
call entityManager.persist(engineer) and be done with it. When switch
to TLE, the database barks because the ID has not been set. Short of
changing the tables to have a default value of nextval($SEQ_NAME), how
do I approach this using TLE?
 
I even tried this:
 
    @Id
    @SequenceGenerator(name = "ENGINEERS_SEQ", allocationSize = 1,
sequenceName = "engineers_seq")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"ENGINEERS_SEQ")
    @Column
    protected Integer id;

based on the documentation here
http://www.oracle.com/technology/products/ias/toplink/jpa/resources/topl
ink-jpa-annotations.html#SequenceGenerator with no love. :)
 
-----
Jason Lee, SCJP
Senior Software Engineer
http://www.iec-okc.com <http://www.iec-okc.com/>