JPA ManyToOne OneToMany Persist Ordering Results In Not Null Violation Constraint
===

Hi have the following two entities:

    public class PromoterUser implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="SEQ_promoter_user_id")
        @SequenceGenerator(name="SEQ_promoter_user_id", sequenceName="SEQ_promoter_user_id", allocationSize=1)
        @Basic(optional = false)
        @Column(name = "promoter_user_id")
        private Long promoterUserId;
        @JoinColumn(name = "promoter_org_id", referencedColumnName = "promoter_org_id")
        @ManyToOne(cascade = CascadeType.PERSIST, optional = false)
        private PromoterOrg promoterOrgId;
        ...
    }

    public class PromoterOrg implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="SEQ_promoter_org_id")
        @SequenceGenerator(name="SEQ_promoter_org_id", sequenceName="SEQ_promoter_org_id", allocationSize=1)
        @Basic(optional = false)
        @Column(name = "promoter_org_id")
        private Long promoterOrgId;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "promoterOrgId")
        private Collection<PromoterUser> promoterUserCollection;
        ...
    }

I establish the bi-directional relationship as follows:

    // Promoter
    PromoterOrg promoterOrg = new PromoterOrg();
    promoterOrg.setCreated(currentDate);
    promoterOrg.setEin("999-9999-999999");

    // PromoterUser
    PromoterUser promoterUser = new PromoterUser();
    promoterUser.setTitle("Boss");
    promoterUser.setCreated(currentDate);

    // Bi-directional here
    promoterUser.setPromoterOrgId(promoterOrg);
    ArrayList<PromoterUser> alPromoterUsers = new ArrayList<>();
    alPromoterUsers.add(promoterUser);
    promoterOrg.setPromoterUserCollection(alPromoterUsers);

When I perform eM.persist(promoterUser), I get the following stacktrace:

    [EL Fine]: 2012-07-27 15:09:29.726--ClientSession(26836706)--Connection(28600858)--Thread(Thread[main,5,main])--INSERT INTO gravy_dev.public.promoter_user (promoter_user_id, created, title, contact_id, created_promoter_user_id, promoter_org_id, user_id) VALUES (?, ?, ?, ?, ?, ?, ?)
	bind => [30, 2012-07-27 15:09:16.107, Boss, null, null, null, null]
    [EL Fine]: 2012-07-27 15:09:29.878--ClientSession(26836706)--Thread(Thread[main,5,main])--SELECT 1
    [EL Warning]: 2012-07-27 15:09:30.003--UnitOfWork(16641111)--Thread(Thread[main,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: org.postgresql.util.PSQLException: ERROR: null value in column "promoter_org_id" violates not-null constraint

It appears that promoterOrg is not persisted and assigned to promoterUser first, resulting in the not-full constraint violation in promoterUser. What am I doing wrong? Thanks!