基础实体类对客体创造的客观化建议

时间:2021-09-04 23:10:56

Sorry For improper question title, i dint get any relevant title for my question.

对不起,对于不正确的问题标题,我得到了我的问题的任何相关标题。

I started using Objectify-Appengine in a new project, I Would like to hear what would be the better solution to create entities from base entity class, consider base class as,

我开始在一个新项目中使用Objectify-Appengine,我想听听从基本实体类创建实体的更好的解决方案,考虑基类为,

@Entity
public Class User { ... some properties...}

then i would like to create some other entities like as below,

然后我想创建一些其他实体,如下所示,

@EntitySubclass
public class AdminUser extends User {}

@EntitySubclass
public class Staff extends User {}

and important point is, i dont want to persist Base Entity "User", meaning there will not be any person of this type.

重要的一点是,我不想坚持基本实体“用户”,这意味着不会有这种类型的人。

is my current solution is good? or is there any better way of doing this?

我目前的解决方案是好的吗?或者有更好的方法吗?

Any Help or suggestion would be helpful.

任何帮助或建议都会有所帮助。

Thanks

1 个解决方案

#1


0  

I'm no objectify expert here, but it seems wrong to me that you have '@Entity public Class User...' if you aren't going to have an entity of type User.

我不是这里的客观专家,但如果您不打算使用User类型的实体,那么您拥有'@Entity public Class User ...'似乎是错误的。

My impression is that you just want to have 2 entity types (Staff and Admin), and you want some shared Java code in a common base class. So you don't need to use @EntitySubclass at all. So how about:

我的印象是,您只想拥有2种实体类型(Staff和Admin),并且您希望在公共基类中使用一些共享Java代码。所以你根本不需要使用@EntitySubclass。那怎么样:

public Class User { ... some properties...}

@Entity
public class AdminUser extends User {}

@Entity
public class Staff extends User {}

#1


0  

I'm no objectify expert here, but it seems wrong to me that you have '@Entity public Class User...' if you aren't going to have an entity of type User.

我不是这里的客观专家,但如果您不打算使用User类型的实体,那么您拥有'@Entity public Class User ...'似乎是错误的。

My impression is that you just want to have 2 entity types (Staff and Admin), and you want some shared Java code in a common base class. So you don't need to use @EntitySubclass at all. So how about:

我的印象是,您只想拥有2种实体类型(Staff和Admin),并且您希望在公共基类中使用一些共享Java代码。所以你根本不需要使用@EntitySubclass。那怎么样:

public Class User { ... some properties...}

@Entity
public class AdminUser extends User {}

@Entity
public class Staff extends User {}