所以我开始和Morphia一起工作,我遇到了一个奇怪的问题。
@Entity("movies")
@Indexes(@Index(value = "Name", fields = @Field("Name")))
@Converters(LocalDateConverter.class)
public class MovieDetails implements Serializable
{
@Id
public String Id;
public String Name;
public String Description;
public String ImageName;
public LocalDate ReleaseDate;
public String Director;
public int Duration;
public String Genres;
public String Actors;
public MovieDetails()
{
}
public MovieDetails(String id, String name, String description, String imageName, String director, String actors, LocalDate releaseDate, String genres, int duration)
{
this (name, description, imageName, director, actors, releaseDate, genres, duration);
Id = id;
}
public MovieDetails(String name, String description, String imageName, String director, String actors, LocalDate releaseDate, String genres, int duration)
{
Name = name;
Description = description;
ImageName = imageName;
Director = director;
Actors = actors;
ReleaseDate = releaseDate;
Genres = genres;
Duration = duration;
}
}
final Morphia morphia = new Morphia();
// tell Morphia where to find your classes
// can be called multiple times with different packages or classes
morphia.mapPackage("nimrodpasha.cinema.objects");
// create the Datastore connecting to the default port on the local host
final Datastore datastore =
morphia.createDatastore(SingleMongoClient.getInstance().getClient(),
Constants.DB.TICKET_DATABASE);
datastore.ensureIndexes();
//region new movie
MovieDetails movie = new MovieDetails("The Mask", "Stanley Ipkiss (Jim Carrey) is a bank clerk that is an incredibly nice man. Unfortunately," +
" he is too nice for his own good and is a pushover when it comes to confrontations. After one of the worst days of his life, he finds a mask that depicts Loki, " +
"the Norse night god of mischief. Now, when he puts it on, he becomes his inner, self: a cartoon romantic wild man. However, a small time crime boss, Dorian Tyrel (Peter Greene), " +
"comes across this character dubbed The Mask by the media. After Ipkiss's alter ego indirectly kills his friend in crime," +
" Tyrel now wants this green-faced goon destroyed.",
"MASK.jpg", "Chuck Russell", "Jim Carrey as Stanley Ipkiss/The Mask,Cameron Diaz as Tina Carlyle,Amy Yasbeck as Peggy Brandt,Joely Fisher as Maggie", new LocalDate(1994, 2, 1), "Action,Comedy,CrimeAction,Family,Fantasy", 88);
//endregion
// Clearing the db first
datastore.delete(datastore.createQuery(MovieDetails.class));
// Saving a new entity and getting the result saved id
String id = (String) datastore.save(movie).getId();
// This returns as null
MovieDetails movieRetrieved = datastore.get(MovieDetails.class, id);
// This returns with one item
List<MovieDetails> allMovies = datastore.createQuery(MovieDetails.class).asList();
get(moviedetails.class,id)
我得到null
当我使用:
我会将I'd字段从String更改为BSON ObjectId字段,MongoDB将在保存时自动分配该字段。如果然后使用ObjectId作为参数进行get调用,它应该可以工作。强烈建议在Mongo中使用ObjectId作为ID字段。
我猜Morphia正试图将一个ObjectId添加到字符串Id字段中,但在某个地方有一个小bug。我将尝试调用datastore.get(example.class,new ObjectId(id)
)。
c.POST请求(使用Postman和contenttype:application/json)... d.执行POST后,MongoDB集合中的数据看起来很好... E.一切都像魅力一样工作,直到这里,SysOut打印出组织新创建的ID... null 感激任何帮助和提前感谢... SG
我发现了这篇文章,其中讨论了是否应该建立文档之间的引用。我想注释我的类,以便在文档中创建引用: 这里,列表先决条件的对象具有对列表BS的对象的引用。在中可能吗?它是如何被称为的(我无法使用关键字“嵌入引用”和“文档内引用”找到任何信息。)Morphia的解决方案会是什么样子? 编辑:我知道引用注释,但它似乎引用了anoter集合,而不是同一个文档中的对象列表。我只想确保序列化的java对象被正确地
我是SNMP新手,我正在尝试使用SNMP操作,我正在使用http://techdive.in/snmp/snmp4j-snmp-get-example代码,但我无法获得预期的输出。我得到如下空响应: SNMP获取演示正在向代理发送请求。。。从代理Snmp获取响应获取响应=[1.3.6.1.2.1.1.1.0=Null] 当我试图为MIB RFC 1213的OID获取sysDescr时,预期的输出应
我尝试将Drools 7.4.1集成到tomcat中的webapp中。 当我调用以下语句以获取KieService时,我得到。 当从测试方法调用相同的方法时,这是正常的。 有人能帮忙吗?
我正在尝试编写一个sokoban求解器,我的代码可以工作,但是计算解决方案需要很多时间。我想这是因为我使用ArrayList,我尝试使用Hashtable,但是方法get不起作用, 因此,当我填充哈希表,并使用键获取列表时,我得到空值。 然而,顶点存在于图形中。 如何解决此问题以提高Sokoban解算器的速度。
我正在开发一个Java的Restful Web应用程序,并计划将MongoDB与吗啡用作ODM。由于我是MongoDB的新手,我需要一些建议。 > 处理db连接的最佳方法是使用db连接池,mongoClient负责处理。 所以我需要重用上面的数据存储,而不是在每次请求时创建一个新实例,因为它会浪费大量资源并影响性能。我应该将上述实现为单例类吗?有人能帮我解决这个问题吗?