0

我正在使用 Play!Framwork 1.2.5。

我正在尝试在我的项目中为模型中的案例实施 CRUD。我按照此处描述的步骤操作,但出现以下错误:

Model models.Media is not managed by any plugin
    at play.db.Model$Manager.factoryFor(Model.java:57)
    at controllers.CRUD$ObjectType.<init>(CRUD.java:215)
    at controllers.CRUD$ObjectType.get(CRUD.java:238)
    at controllers.CRUD$ObjectType$get.call(Unknown Source)
    at {module:crud}/app/views/tags/crud/types.tag.(line:4)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:247)
    at play.templates.GroovyTemplate$ExecutableTemplate.invokeTag(GroovyTemplate.java:401)
    at {module:crud}/conf/routes.(line:4)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:247)
    at play.templates.Template.render(Template.java:26)
    at play.templates.GroovyTemplate.render(GroovyTemplate.java:202)
    at play.mvc.Router.parse(Router.java:162)
    at play.mvc.Router.parse(Router.java:190)
    at play.mvc.Router.parse(Router.java:164)
    at play.mvc.Router.load(Router.java:48)
    at play.mvc.Router.detectChanges(Router.java:219)
    at Invocation.HTTP Request(Play!)

这是类媒体的代码:

import org.hibernate.annotations.Entity;
import org.hibernate.annotations.GenericGenerator;
import play.db.jpa.Model;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;

@Entity
public class Media extends Model{
    @Id
    private String uuid;

    @OneToOne
    private Video video;
    @OneToOne
    private Picture picture;

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String id) {
        this.uuid = id;
    }


    public Video getVideo() {
        return video;
    }

    public void setVideo(Video video) {
        this.video = video;
    }

    public Picture getPicture() {
        return picture;
    }

    public void setPicture(Picture picture) {
        this.picture = picture;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Media))
            return false;
        Media media = (Media) obj;
        return media.getUuid().equals(this.uuid);
    }
}
4

1 回答 1

0

我认为您没有使用正确的导入语句。

您对模型的导入Media.java应如下所示:

媒体模型

import play.db.jpa.Model;

// should import javax.persistence.* package rather than org.hibernate.*
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;

@Entity
public class Media extends Model {
   ....
}

如果您使用关系注释(如@OneToOne)标记了字段,则应将对象定义为Entity. 因此,您的其他模型,例如Picture.javaVideo.java应该导入相同类型的模型,Media.java如下所示:

图片模型

import play.db.jpa.Model;

// don't forget to import javax.persistence.* package
import javax.persistence.Entity;

@Entity
public class Picture extends Model {
   ...
}

视频模型

import play.db.jpa.Model;

// don't forget to import javax.persistence.* package too
import javax.persistence.Entity;


@Entity
public class Video extends Model {
   ...
}

我已经尝试过了,它适用于我。希望它有助于解决您的问题。问候。

于 2013-04-09T14:27:33.903 回答