FYI: Taking Joe Ottinger's advice (credit where credit is due! :), I
switched from a SequenceGenerator to a TableGenerator, and it worked, so
it looks like TopLink doesn't like PostgreSQL sequences at the moment.
:\
--
Jason Lee
Programmer/Analyst
-----Original Message-----
From: Jason Lee
Sent: Wednesday, June 07, 2006 6:13 PM
To: ejb_at_glassfish.dev.java.net
Subject: JPA Primary Key Generation Issue
I'm trying to persist a new object, but I keep getting this error:
ERROR: null value in column "id" violates not-null constraint
My bean looks like this:
@Entity
@Table(name="jobs")
@SequenceGenerator(name="JOBS_SEQ", allocationSize=1,
sequenceName="jobs_seq")
public class Job implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,
generator="JOBS_SEQ")
private Integer id;
// ...
}
And the DAO code trying to save the bean is this:
EntityManager em = emf.createEntityManager();
EntityTransaction txn = em.getTransaction();
txn.begin();
em.persist(job);
txn.commit();
The sequence is defined in the database, and the user configured in the
persistence unit has ownership of the sequence (as well as the table).
What am I doing wrong? Everything looks right from the examples I can
find, but it's certainly not working. :(
--
Jason Lee
Programmer/Analyst
---------------------------------------------------------------------
To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net