开发者

JPA OneToOne like dependency

I'm trying Play Framework, now I have this situation:

I have a SuperUser who is a Person with power, and I want to do this Persona entity like FK and so like primary key for SuperUsuario entity, now I have i开发者_StackOverflowt:

@Entity(name = "SUPERUSUARIO")
public class Superusuario extends Model {

    @OneToOne
    public Persona persona;

    public Superusuario(Persona persona) {
        this.persona = persona;
    }

but the framework create a field ID por any entity, how can I get Persona like PK for SuperUsuario??

thanks for any help


Two things :

  1. Why would you want to specify a PK for this? Really? Why would you PK be better than the ID field PlayFramework generates for you? If you want, you can add a index for performance b ut I doubt that will help you anyway.

  2. Why do it that way? A superuser is a person with power. Thus create a superuser containing a user? Why not use the possibilites giving by Java and all the other object oriented programming languages by the way? Polymorphism. You superuser could be an extended user. Much better that way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜