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