请帮我解决以下问题...... this.save()抛出错误:
类型[class model.db.bean.accounting.CustomerTable]不是 注册实体?
但是这个bean已经注册,并且数据检索在使用相同的bean时工作正常......
问题与link ...
不同错误:
play.api.Application$$anon$1: Execution exception[[PersistenceException: The type [class model.db.bean.accounting.CustomerTable] is not a registered entity? If you don't explicitly list the entity classes to use Ebean will search for them in the classpath. If the entity is in a Jar check the ebean.search.jars property in ebean.properties file or check ServerConfig.addJar().]]
at play.api.Application$class.handleError(Application.scala:296) ~[play_2.11-2.3.8.jar:2.3.8]
at play.api.DefaultApplication.handleError(Application.scala:402) [play_2.11-2.3.8.jar:2.3.8]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [play_2.11-2.3.8.jar:2.3.8]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [play_2.11-2.3.8.jar:2.3.8]
at scala.Option.map(Option.scala:145) [scala-library-2.11.1.jar:na]
CustomerTable:
package model.db.bean.accounting;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import play.db.ebean.Model;
@Table(name = "accounting.customer")
@Entity
public class CustomerTable extends Model {
private static final long serialVersionUID = 1L;
private String customerId;
private String accountId;
private String accountUsername;
public CustomerTable()
{
super();
}
public CustomerTable create(controllers.beans.Customer cCustomers) {
this.customerId = cCustomers.getCustomerId();
this.accountId = cCustomers.getAccountId();
this.accountUsername = cCustomers.getAccountUsername();
this.save();
return this;
}
@Id
@GeneratedValue
@Column(name="customer_id")
public String getCustomerId() {
return customerId;
}
@Column(name="account_id")
public String getAccountId() {
return accountId;
}
@Column(name="account_username")
public String getAccountUsername() {
return accountUsername;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public void setAccountId(String accountId) {
this.accountId = accountId;
}
public void setAccountUsername(String accountUsername) {
this.accountUsername = accountUsername;
}
}
App config:
...
ebean.accounting="model.db.bean.accounting.*"
..
答案 0 :(得分:0)
解决了这个问题!...我必须将数据库名称作为参数传递给“保存”功能......就像这样......
public CustomerTable create(controllers.beans.Customer cCustomers) {
this.customerId = cCustomers.getCustomerId();
this.accountId = cCustomers.getAccountId();
this.accountUsername = cCustomers.getAccountUsername();
//Pass schema name as parameter
this.save("accounting");
return this;
}
答案 1 :(得分:0)
我认为您应该将导入更改为
import com.avaje.ebean.Model;
此问题将得到解决。 其他想法
在你的App配置中:
ebean.default = "models.db.ebean.*"