Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.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
Mongodb 莫菲娅·蒙哥达——”;请为用户标记的Id字段实体“重写此方法”;_Mongodb_Playframework_Morphia - Fatal编程技术网

Mongodb 莫菲娅·蒙哥达——”;请为用户标记的Id字段实体“重写此方法”;

Mongodb 莫菲娅·蒙哥达——”;请为用户标记的Id字段实体“重写此方法”;,mongodb,playframework,morphia,Mongodb,Playframework,Morphia,我正在关注关于的教程,但我的示例未能给出以下跟踪: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.google.code.morphia.mapping.MappedClass.callLifecycleMethods(MappedClass.java:323) at com.google.code.morphia.mapping.Mapper.toDBObject(M

我正在关注关于的教程,但我的示例未能给出以下跟踪:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.google.code.morphia.mapping.MappedClass.callLifecycleMethods(MappedClass.java:323)
    at com.google.code.morphia.mapping.Mapper.toDBObject(Mapper.java:371)
    at com.google.code.morphia.DatastoreImpl.entityToDBObj(DatastoreImpl.java:674)
    at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:722)
    at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:802)
    at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:796)
    at models.com.vlist.activity.classes.TestMongoData.testUserData(TestMongoData.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.code.morphia.mapping.MappedClass.callLifecycleMethods(MappedClass.java:304)
    ... 28 more
Caused by: java.lang.UnsupportedOperationException: Please override this method for user marked Id field entity: models.com.vlist.activity.classes.User
    at play.modules.morphia.Model.setId_(Model.java:284)
    at play.modules.morphia.Model.generateId_(Model.java:299)
    ... 33 more  
我的例子如下:

import javax.persistence.Entity;

import org.bson.types.ObjectId;

import com.google.code.morphia.Datastore;
import com.google.code.morphia.Morphia;
import com.google.code.morphia.annotations.Id;

import play.modules.morphia.Model;

@Entity
public class User extends Model {

    @Id ObjectId id;    
    private String firstName;
    private String lastName;

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getFirstName(){
        return firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getLastName() {
        return lastName;
    }
}
08:01:55,783 ERROR ~ 

@66h1bm10d
Internal Server Error (500) for request GET /@tests

Compilation error (In {module:morphia}/app/morphia/Filter.java around line 8)
The file {module:morphia}/app/morphia/Filter.java could not be compiled. Error raised is : The type Filter is already defined

play.exceptions.CompilationException: The type Filter is already defined
    at play.classloading.ApplicationCompiler$2.acceptResult(ApplicationCompiler.java:246)
    at org.eclipse.jdt.internal.compiler.Compiler.handleInternalException(Compiler.java:672)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:516)
    at play.classloading.ApplicationCompiler.compile(ApplicationCompiler.java:278)
    at play.classloading.ApplicationClassloader.getAllClasses(ApplicationClassloader.java:406)
    at play.Play.start(Play.java:453)
    at play.Play.detectChanges(Play.java:574)
    at play.Invoker$Invocation.init(Invoker.java:186)
    at Invocation.HTTP Request(Play!)

import static org.junit.Assert.*;

import org.junit.Test;

import com.google.code.morphia.Datastore;
import com.google.code.morphia.Morphia;

public class TestMongoData {

    @Test
    public void testUserData() {
        User user = new User();
        user.setFirstName("first");
        user.setLastName("last");

        Morphia morphia = new Morphia();
        Datastore ds = morphia.createDatastore("testData");
        ds.save(user);

    }
}  
有什么不对劲吗

更新: 当我使用
播放测试
时,我看到以下内容:

import javax.persistence.Entity;

import org.bson.types.ObjectId;

import com.google.code.morphia.Datastore;
import com.google.code.morphia.Morphia;
import com.google.code.morphia.annotations.Id;

import play.modules.morphia.Model;

@Entity
public class User extends Model {

    @Id ObjectId id;    
    private String firstName;
    private String lastName;

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getFirstName(){
        return firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getLastName() {
        return lastName;
    }
}
08:01:55,783 ERROR ~ 

@66h1bm10d
Internal Server Error (500) for request GET /@tests

Compilation error (In {module:morphia}/app/morphia/Filter.java around line 8)
The file {module:morphia}/app/morphia/Filter.java could not be compiled. Error raised is : The type Filter is already defined

play.exceptions.CompilationException: The type Filter is already defined
    at play.classloading.ApplicationCompiler$2.acceptResult(ApplicationCompiler.java:246)
    at org.eclipse.jdt.internal.compiler.Compiler.handleInternalException(Compiler.java:672)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:516)
    at play.classloading.ApplicationCompiler.compile(ApplicationCompiler.java:278)
    at play.classloading.ApplicationClassloader.getAllClasses(ApplicationClassloader.java:406)
    at play.Play.start(Play.java:453)
    at play.Play.detectChanges(Play.java:574)
    at play.Invoker$Invocation.init(Invoker.java:186)
    at Invocation.HTTP Request(Play!)

尝试删除
@Id ObjectId来自您的模型。Morphia Play模块框架将为您添加id

然后将字段公开并删除getter/setter方法

public String firstName;
public String lastName;
此外,您的实体导入不正确。试试这个

import com.google.code.morphia.annotations.Entity;
对于测试用例,请尝试以下操作:

import static org.junit.Assert.*;

import org.junit.Test;
import play.test.UnitTest;

public class TestMongoData extends UnitTest {

    @Test
    public void testUserData() {
        User user = new User();
        user.setFirstName("first");
        user.setLastName("last");

        user.save();
    }
}  

尝试删除
@Id ObjectId来自您的模型。Morphia Play模块框架将为您添加id

然后将字段公开并删除getter/setter方法

public String firstName;
public String lastName;
此外,您的实体导入不正确。试试这个

import com.google.code.morphia.annotations.Entity;
对于测试用例,请尝试以下操作:

import static org.junit.Assert.*;

import org.junit.Test;
import play.test.UnitTest;

public class TestMongoData extends UnitTest {

    @Test
    public void testUserData() {
        User user = new User();
        user.setFirstName("first");
        user.setLastName("last");

        user.save();
    }
}  

问题来自您的@Entity定义。您正在使用JPA注释,而您应该使用Morphia注释


启动时,Morphia插件将检索标记有Morphia实体注释的所有类,并使用各种注入模型方法增强它们。您收到此异常是因为您的模型类尚未增强

问题来自您的@Entity定义。您正在使用JPA注释,而您应该使用Morphia注释


启动时,Morphia插件将检索标记有Morphia实体注释的所有类,并使用各种注入模型方法增强它们。您收到此异常是因为您的模型类尚未增强

似乎您已经在依赖项文件和应用程序配置文件中定义了morphia模块

在依赖项文件中:-play->morphia[1.2.1beta6,)

在应用程序配置文件中:module.morphia=${play.path}/modules/morphia


您必须删除其中一个声明,否则morphia模块将加载两次…

看起来您已经在依赖项文件和应用程序配置文件中定义了morphia模块

在依赖项文件中:-play->morphia[1.2.1beta6,)

在应用程序配置文件中:module.morphia=${play.path}/modules/morphia


您必须删除其中一个声明,否则morphia模块将被加载两次…

如果您注释@Id,那么play morphia将不会通过为void setId(Object Id)方法提供正确的实现来增强您的模型。请尝试像这样自己定义一个

@Entity
class User extends Model {
  @Id String email;

  protected void setId_(Object id) {
  }
}

如果您注释@Id,那么play morphia将不会通过为void setId(Object Id)方法提供正确的实现来增强您的模型

@Entity
class User extends Model {
  @Id String email;

  protected void setId_(Object id) {
  }
}

我试图删除@Id ObjectId Id;但仍然存在相同的错误:(@daydreamer查看我编辑的答案。尝试将字段公开。@daydreamer还检查实体导入不走运:(,两者都做了,添加了public修饰符而不是private,并标记为import com.google.code.morphia.annotations.Entity;@daydreamer尝试不同的测试用例。然后在杀死当前的测试用例后再次运行
play test
。我尝试删除@Id ObjectId;但仍然出现相同的错误:(@daydreamer查看我编辑的答案。尝试将字段公开。@daydreamer还检查实体导入没有运气:(,两者都做了,添加了公共修饰符而不是私有修饰符,并标记为import com.google.code.morphia.annotations.Entity;@daydreamer尝试不同的测试用例。然后在杀死当前测试用例后再次运行
play test
)。