我正在谷歌应用引擎上尝试objectify(版本2.2.3)嵌入式类示例(wiki).我收到此错误:
java.lang.IllegalArgumentException: one: com.mypkg.LevelOne is not a supported property type.
at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedSingleValue(DataTypeUtils.java:184)
我的代码与Wiki中的代码相同.控制器中的部分:
EntityWithEmbedded ent = new EntityWithEmbedded();
ent.one = new LevelOne();
ent.one.foo = "Foo Value";
ent.one.two = new LevelTwo();
ent.one.two.bar = "Bar Value";
EntityWithEmbedded类:
import javax.jdo.annotations.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class EntityWithEmbedded {
@Id public Long id;
@Embedded public LevelOne one;
//getter & setters here
}
班级一级:
import javax.persistence.Embedded;
public class LevelOne {
public String foo;
public @Embedded LevelTwo two;
//getter & setters here
}
Class LevelTwo: …
我正在使用Objectify和我的第一个严肃的Google App Engine项目,而且一般都是游泳(这是一个可爱的图书馆!).不幸的是,我在坚持我的实体时遇到了一个问题.
我的基本结构如下:
@Entity
class Parent {
@Id
long id = 123;
@Embedded
Child[] children;
}
@Entity
class Child {
@Id
Long id;
}
Run Code Online (Sandbox Code Playgroud)
我手动声明父实体的id,但我希望嵌入的子实体自动生成id.我确实想知道只是完全删除子实体中的@Id并围绕它编码,但后来我得到了需要@Id的实体的错误.
有人可以帮忙吗?我正在使用id,以便比较父实体的子节点之间的变化,因此它对我设计它的当前方式来说是相当基础的.我可以重新设计,如果这是一个更好的解决方案.
好吧,我说我正在为以下足球俱乐部建模:所有人都是个人.玩家是一个人,因此扩展个人.会员是一个人,因此扩展个人.
超类:
Individual {name, eyeColour}
Run Code Online (Sandbox Code Playgroud)
子类:
Player extends Individual {position}
Member extends Individual {subscription}
Run Code Online (Sandbox Code Playgroud)
汤姆是足球俱乐部的老板:
Individual i = new Individual("Tom", "Blue")
Run Code Online (Sandbox Code Playgroud)
鲍勃和托尼是球员:
Player p1 = new Player("Bob", "Green", "Goalkeeper")
Player p2 = new Player("Tony", "Blue", "Striker")
Run Code Online (Sandbox Code Playgroud)
史蒂夫是会员:
Member m = new Member("Steve", "Brown", 5.00)
Run Code Online (Sandbox Code Playgroud)
个人,玩家和成员都使用Objectify持久保存到GAE数据库中的同一种(个体).
name eyeColour position subscription ^d
Tom Blue [missing] [missing] Individual
Bob Green Goalkeeper [missing] Player
Tony Blue Striker [missing] Player
Steve Brown [missing] 5.00 Member
如果Bob决定成为会员以及玩家怎么办?我想存储是订阅.我无法将鲍勃贬低为个人,然后向成员倾斜.Java不允许这样做.我无法创建新成员并复制Bob的Player对象的所有属性并将其存储回相同的ID - 我将失去他的Position属性.我需要Bob成为数据库中的成员和播放器,但不是对象形式(我不是在多重继承之后)我仍然希望获得(Player.class,"Bob")并拥有一个Player对象或获取(Member.class,"Bob")并有一个Member对象.我不需要同时具有位置和订阅属性的Object.
我也想避免这是数据存储区:
name eyeColour position subscription ^d
Tom … getCursor()javadoc说:
返回:一个Cursor;如果无法恢复此查询结果,则返回null
"恢复"这个词在上下文中意味着什么?
我的代码如下:
com.googlecode.objectify.cmd.Query q = createQuery();
QueryResultIterator<T> itr = q.iterator();
while( itr.hasNext() )
{
list.add( itr.next() );
}
...
String newCursorValue = itr.getCursor().toWebSafeString();
Run Code Online (Sandbox Code Playgroud)
它抛出NPE只是因为itr.getCursor()是emtpy.这种方法很长一段时间都运行良好,但是当我修改查询条件(但它有效)时,今天失败了.但我不明白为什么查询条件会影响getCursor()方法.
有人请说清楚吗?顺便说一下,我使用GAE/J v1.7.1,Objectify 4a3.
Objectify的save().entity(E entity).now()方法返回Key<E>已保存的entity,这在第一次保存新实体时很有用.到现在为止还挺好.
但是,保存已存在于数据存储区中的实体时,此方法返回的内容并不完全清楚,或者返回值是否可以告诉我该写入是否成功.根据这些javadoc,我能否认为它是成功的,除非RuntimeException被抛出?如果是这样,无论写入是否在事务内,都是真的吗?
具体来说,我正在阅读,然后使用Objectify在XG事务中修改和保存两个实体.我正在检查第一次保存的返回值,然后保存第二次,如下所示:
if(ofy().save().entity(entA).now() != null) {
ofy().save().entity(entB).now();
}
Run Code Online (Sandbox Code Playgroud)
首先,我想第一件事是我应该用一个ofy().save().entities(ent1, ent2).now()电话保存这些?
其次,检查ofy().save().entity().now()调用的返回值对我来说是否有意义:
ConcurrentModificationException但是如果事务提交一直失败会发生什么,则会重试?)感谢任何人都可以给予的澄清.
我正在使用Google App engine1.9.3,Eclipse,Objectify5.03.我的班级如下:
import com.googlecode.objectify.Ref;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Load;
@Entity
public class User {
@Id private Long userId;
private String userName;
@Load private Ref<UserDetails> userDetails;
@Load private Ref<UserPassword> userPassword;
//getters & setters
}
Run Code Online (Sandbox Code Playgroud)
当我尝试通过Eclipse为此类创建google端点时,我收到以下错误: java.lang.IllegalArgumentException:参数化类型com.googlecode.objectify.Ref不支持
这是我第一次尝试Objectify.
我有什么不妥的想法.从我到目前为止所阅读的内容来看,GAE端点和Objectify应该有效,对吗?
我试图在spss文件后面读取xml,我想从etree转向objectify.
如何在下面转换此函数以返回物体对象?我想这样做是因为客观化xml对象对我(作为新手)更容易使用,因为它更加pythonic.
def get_etree(path_file):
from lxml import etree
with open(path_file, 'r+') as f:
xml_text = f.read()
recovering_parser = etree.XMLParser(recover=True)
xml = etree.parse(StringIO(xml_text), parser=recovering_parser)
return xml
Run Code Online (Sandbox Code Playgroud)
我失败的尝试:
def get_etree(path_file):
from lxml import etree, objectify
with open(path_file, 'r+') as f:
xml_text = objectify.fromstring(xml)
return xml
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
lxml.etree.XMLSyntaxError: xmlns:mdm: 'http://www.spss.com/mr/dm/metadatamodel/Arc 3/2000-02-04' is not a valid URI
Run Code Online (Sandbox Code Playgroud) 我在api explorer中遇到GAE问题.我正在尝试使用objectify保存到数据存储区但是我收到此错误:
{
"error": {
"message": "java.lang.NoClassDefFoundError: Could not initialize class Project.service.OfyService",
"code": 503,
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "java.lang.NoClassDefFoundError: Could not initialize class Project.service.OfyService"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我试着谷歌一堆但空手而归.我是GAE的新手,对Java有点新鲜.这是在intelliJ的控制台中显示的内容:
java.lang.NoClassDefFoundError: Could not initialize class Project.service.OfyService
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestrict ed(RuntimeHelper.java:70)
at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)
at Project.saveProfile(ProjectApi.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:359)
at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:160)
at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) …Run Code Online (Sandbox Code Playgroud) java google-app-engine maven objectify google-cloud-datastore
我很难用Objectify查询GeoPt字段。
我确保在GeoPt字段上有一个@Index注释。
但是,下面的语句似乎不起作用
ofy().load()
.type(GeoStat.class)
.filter("geoPt.latitude >=", neLat)
.limit(10);
Run Code Online (Sandbox Code Playgroud)
在Objectify中可以查询GeoPt字段吗?
在将我的代码部署到云后使用google appengine时出现此错误,我使用objectify索引进行过滤.
这是我的包含索引的java类(Entity)文件
@Entity
public class Session{
@Index private Integer year;
@Index private Key<Institute> institute;
//some other manipulation goes below
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用objectify从数据存储区调用实体列表时
ofy().load().type(Session.class).filter("institute",t).order("year").list();//order by year
Run Code Online (Sandbox Code Playgroud)
它在我的控制台上抛出以下错误,下面的图像显示它,抱歉不太清楚