0

pleskの「コンピュータデータベース」サンプルアプリケーションにoracle10gとebeansを使用しようとしています。しかし、データベースに新しいコンピューターを挿入しようとすると、次のエラーが発生します。

[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私は別のようAUTOに 試しIDENTITYましたが、何も機能しません...

編集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値を確認してください。@see http://www.techonthenet.com/oracle/errors/ora00001.php

私の英語でsory。: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 に答える