I have the following simple webservice declared as @Stateless EJB running on GlassFish 3.1.2.2 with EclipseLink 2.4.1 using a JTA DataSource to connect to a MySQL database:
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response update(TimeRow e) throws Exception {
    if ((e.getKey() == null) || !e.getKey().keyValid()) {
        return Response.status(400).build();
    }
    TimeRow existing = em.find(TimeRow.class, e.getKey());
    if (existing == null) {
        em.persist(e);
    } else {
        existing.setValues(e.getValues());
        em.flush();
    }
    return Response.status(204).build();
}
Entity class of TimeRow:
@Entity
@NamedQueries({
    @NamedQuery(name="TimeRow.findAllByUser",
         query="SELECT t FROM TimeRow t WHERE t.table.userId = :uid")
})
public class TimeRow implements Serializable {
    @EmbeddedId
    private TimeRowPK key;
    @MapsId("userId")
    @JoinColumn(name = "USERID", referencedColumnName = "userId")
    @ManyToOne
    private UserTable table;
    @Column(name="ROWVALUES")
    private List<Double> values;
    public TimeRow() {
        this.key = new TimeRowPK();
        this.values = new ArrayList<Double>(20);
        extendValuesTo20();
    }
    public TimeRow(String uid, Date date) {
        this.key = new TimeRowPK(date, uid);
        this.table = new UserTable(uid);
        this.values = new ArrayList<Double>(20);
        extendValuesTo20();
    }
    public List<Double> getValues() {
        return values;
    }
    public void setValues(List<Double> values) {
        this.values = values;
        extendValuesTo20();
    }
    private void extendValuesTo20() {
        if (this.values.size() < 20) {
             for (int i = this.values.size(); i < 20; i++) {
                  this.values.add(0.0);
             }
        }
    }
}
@EmbeddableId TimeRowPK:
@Embeddable
public class TimeRowPK implements Serializable {
    public TimeRowPK() { }
    public TimeRowPK(Date date, String userId) {
        this.date = date;
        this.userId = userId;
    }
    @Column(name="DAY")
    private Date date;
    @Column(name = "USERID")
    private String userId;
    public boolean keyValid() {
        return ((date != null) && ((userId != null) && !userId.isEmpty()));
    }
}
persistence.xml (without the <persistence> tag):
<persistence-unit name="test" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/test</jta-data-source>
    <class>com.test.TimeRow</class>
    <class>com.test.TimeRowPK</class>
    <class>...</class>
    <properties>
        <property name="eclipselink.ddl-generation" value="create-tables" />
        <property name="eclipselink.ddl-generation.output-mode" value="database" />
    </properties>
</persistence-unit>
Webservice declaration:
@Path("row")
@Stateless
public class TimeRowWebService {
    @PersistenceContext(unitName = "test")
    private EntityManager em;
    ...
}
The problem is that if the entity exists, the changes get stored only in the PersistenceContext, but they are not committed to the database. Meaning that I can retrieve the correct data with the changes, but for example if I restart the AS, the changes are gone. There are no errors in the AS log.
So I guess I have to do some bean level manual transaction handling to get this work. What exactly do I have to add to get this working?
 
     
    