0

我正在尝试将 oracle 10g 和 ebeans 用于 plesk 的“计算机数据库”示例应用程序。但是当我尝试在数据库中插入一台新计算机时,我得到了这个错误:

[PersistenceException: ERROR executing DML bindLog[] error[ORA-00001: Unique key constraint violation (PLAY.PK_COMPANY)\n ]]

在以下行:

{ 
 Form<Computer> computerForm = form(Computer.class).bindFromRequest();
        if(computerForm.hasErrors()) {
            return badRequest(createForm.render(computerForm));
        }
       computerForm.get().save(); //HERE
        flash("success", "Computer " + computerForm.get().name + " has been created");
       return GO_HOME;
}

这里有我的对象声明:

@Entity 
@Table(name="COMPUTER")
@SequenceGenerator(name = "computer_seq", sequenceName = "computer_seq")
public class Computer extends Model {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long id;

    @Constraints.Required
    @Column(name="name")
    public String name;

    @Column(name="introduced")
    public String introduced;

    @Column(name="discontinued")
    public String discontinued;

    @ManyToOne(cascade = CascadeType.MERGE)
    public Company company;

    /**
     * Generic query helper for entity Computer with id Long
     */
    public static Finder<Long,Computer> find = new Finder<Long,Computer>(Long.class, Computer.class); 

    /**
     * Return a page of computer
     *
     * @param page Page to display
     * @param pageSize Number of computers per page
     * @param sortBy Computer property used for sorting
     * @param order Sort order (either or asc or desc)
     * @param filter Filter applied on the name column
     */
    public static Page<Computer> page(int page, int pageSize, String sortBy, String order, String filter) {
        return 
            find.where()
                .ilike("name", "%" + filter + "%")
                .orderBy(sortBy + " " + order)
                .fetch("company")
                .findPagingList(pageSize)
                .getPage(page);
    }

}

编辑1: 我尝试了不同的GeneratedValue strategy喜欢AUTOIDENTITY但没有任何效果....

编辑 2: 我尝试使用Sequence策略,但它也不起作用:

@SequenceGenerator(name = "computer_seq", sequenceName = "computer_seq", initialValue=1, allocationSize=100)
[...]
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="computer_seq")
    public Long id;

编辑 3: 这里有公司实体:

@Entity 
@Table(name="COMPANY")
@SequenceGenerator(name = "company_seq", sequenceName = "company_seq", initialValue=1, allocationSize=100)
public class Company extends Model {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long id;

    @Constraints.Required
    @Column(name="name")
    public String name;

    /**
     * Generic query helper for entity Company with id Long
     */
    public static Model.Finder<Long,Company> find = new Model.Finder<Long,Company>(Long.class, Company.class);

    public static Map<String,String> options() {
        LinkedHashMap<String,String> options = new LinkedHashMap<String,String>();
        for(Company c: Company.find.orderBy("name").findList()) {
            options.put(c.id.toString(), c.name);
        }
        return options;
    }

}

我尝试了一个SEQUENCE strategy并且AUTO strategy它也不起作用。

4

1 回答 1

0

当您在同一张表上保存重复的 id 时出现此错误

保存前检查 id 值。@参见 http://www.techonthenet.com/oracle/errors/ora00001.php

我的英语很抱歉。:D

编辑 :

违反唯一键约束 (PLAY.PK_COMPANY) 也尝试检查 COMPANY 实体的自动生成序列。

编辑 :

将 Company Generate 更改为 @GeneratedValue(strategy=GenerationType.AUTO,generator="company_seq") 或更改为 @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="company_seq")

于 2013-01-11T16:17:28.520 回答