我正在尝试将 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
喜欢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
它也不起作用。