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
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 )