Hi. What database are you using, and how have you created the db schema?
I might be guessing here, but for me it looks like the id column is a kind of "identity" in db2, or maybe "auto_increment" in mysql. The exception is a JDBC exc, not JPA. Your id is specified not to be GenerationType.IDENTITY. Maybe this is the problem?
Please paste the ddl for the DEPARTAMET1 table, right now I think we have too little info.
I think Raf is on the good track. I think that an identity column will be generated for your ID fields.
Try to check the DDL of the created table. It might look like something like this :
In that case, you cannot set the ID manually. What you can do is either :
- Use the @GeneratedValue annotation with GenerationType.IDENTITY
- or Do not let the container create tables automatically, and make them yourself, without using "GENERATED ALWAYS AS IDENTITY"
As Christphe says, you should just get rid of these setId() setter methods, and make it work with no other changes to the code. Have you tried this before?
Thanks at last i was able to test persist Department1 entity and was able to ManyToOne relation ship successfully.What i did is i manually deleted tables using ij and then persisted again that solved the problem.