While testing an entity bean mapped to a Postgresql database table I recieved
some "duplicate key violates unique constraint" errors. The errors occured
during concurrant access to the database by jboss and psql using different
database roles. After setting the SequenceGenerator annotation attribute
allocationSize = 1 this issue was resolved.
| // database table
| CREATE TABLE people (
| id SERIAL PRIMARY KEY
| , name VARCHAR(32)
| );
| // CREATE TABLE will create implicit sequence "people_id_seq" for serial
column "people.id"
|
| // entity bean
| @Entity
| @Table(name = "people", schema = "public")
| public class People implements Serializable
| {
| private static final long serialVersionUID = 1234L;
| private int id;
| private String name;
|
| public People() {}
|
| @Id
| @SequenceGenerator(name = "identifier", sequenceName = "people_id_seq",
initialValue = 1, allocationSize = 1)
| @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"identifier")
| @NotNull
| public int getId()
| {
| return id;
| }
|
| public void setId(int id)
| {
| this.id = id;
| }
|
| @Column(name = "name", length = 32)
| @Length(max = 32)
| public String getName()
| {
| return this.name;
| }
|
| public void setName(String name)
| {
| this.name = name;
| }
| }
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3997615#3997615
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3997615
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user