socksocket
socksocket

Reputation: 4371

Play! framework with Ebean: PersistenceException

I have a Topic class which extends Model.
creating the first record of table topics is fine, but it is failing to create another record:

[PersistenceException: ERROR executing DML bindLog[] error[ERROR: duplicate key value violates unique constraint "pk_topics"\n Detail: Key (id)=(1) already exists.]]

the exception occur of course at this line:

topic.save();

this is weird because:

  1. it worked before without a problem.
  2. the attribute id is defined with the a annotation @Id which suppose to auto increment to the next value, but I get exception about duplicate id.

what should I do to solve this problem?

class Model (not all of course, only what's relevant):

@Entity
@Table (name = "topics")
public class Topic extends Model {
@Id
public long id;
public String title;
public String content;
@ManyToOne
@JoinColumn(name = "forumId")
public Forum forum;
@ManyToOne
@JoinColumn(name = "userId")
public User user;
public Date date;

public static void create(Topic topic) {
    topic.save();
}

Upvotes: 2

Views: 1593

Answers (1)

socksocket
socksocket

Reputation: 4371

I found out the solution. when I changed back the access modifier of id to protected it worked again. weird, but now it works perfectly.

explanation?

Upvotes: 1

Related Questions