Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Playframework 2.0 如何正确地从抽象类扩展类_Playframework 2.0_Ebean - Fatal编程技术网

Playframework 2.0 如何正确地从抽象类扩展类

Playframework 2.0 如何正确地从抽象类扩展类,playframework-2.0,ebean,Playframework 2.0,Ebean,你好,我有类似的东西 @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Person extends Model { @Id public int id; public String name; public String lastName; } 及 我不能这样做,因为我得到一个错误,dtype不能为null,但我不能设置它(或者我只是不知道如何做) 第二件事是,

你好,我有类似的东西

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Person extends Model {
@Id  
public int id;

public String name;

public String lastName;
}

我不能这样做,因为我得到一个错误,dtype不能为null,但我不能设置它(或者我只是不知道如何做)

第二件事是,如果我从db中添加用户,我无法通过id获取他,当我这样做时,我获取sql错误,因为where子句如下所示

User user = new User();
user.name = "Dawid";
user.save();
WHERE t0. AND t0.id = 1

如你所见,有t0。点后没有任何内容,这会破坏一切,我不知道它在那里做什么。有关信息,请不要使用
User
作为表名,因为它是许多数据库服务器中的关键字:

@Entity
@Table(name = "myUserTable")
public class User extends Person {
...
}
但这不是你的问题。好的,Ebean只支持
SINGLE_TABLE
策略,因此您必须使用此策略,并且您可以使用
@DiscriminatorValue
注释在子类上指定鉴别器(即
dtype
)名称:

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class Person extends Model {
...
}

@Entity
@DiscriminatorValue("aUser")
public class User extends Person {
...
}
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class Person extends Model {
...
}

@Entity
@DiscriminatorValue("aUser")
public class User extends Person {
...
}