I\'ve updated the question so that both tables now use auto-increment. Is perhaps the problem in persisting to the MESSAGES
table a problem wi
The AUTO strategy is an alias for NATIVE if your database supports it, or SEQUENCE if your database supports it, or TABLE if your database doesn't support any of those.
So if the database doesn't support NATIVE and SEQUENCE, then you need to create the table that EclipseLink uses to generate IDs.
With MySQL, NATIVE should be supported. You need to make the ID column an auto_increment column, though. Make sure to configure the appropriate DatabasePlatform as well.
For mysql
I would recommend you following:
At you table messages
at field id
add declaration auto_increment
:
create table messages(
...
id int not null auto_increment,
...
primary key (id)
)
At entity declaration use
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
This talks to JPA use auto-increment feature of MySQL
If it is not applicable (for example you may want to create related another entity in the same transaction) use TABLE strategy (for more details see http://www.objectdb.com/java/jpa/entity/generated )