我是一个客观化的新手,所以我知道一些事情,但我已经定义了他们在最佳实践中描述的服务
package com.hmt1.objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.ObjectifyFactory;
import com.googlecode.objectify.Objectify;
import com.hmt1.entities.User;
import com.hmt1.entities.Match;
public class OfyService {
static {
factory().register(User.class);
factory().register(Match.class);
// factory().register(OtherThing.class);
}
public static Objectify ofy() {
return ObjectifyService.ofy();
}
public static ObjectifyFactory factory() {
return ObjectifyService.factory();
}
}
我认为我的静态导入是正确的吗?
import static com.hmt1.objectify.OfyService.ofy;
public class UserOperations {
public boolean isEmailInUse(String email) {
try {
User user = ofy().load().type(User.class).filter("email", email).first().get();
if (user == null )
return false;
else
return true;
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("email in use exception");
return false;
}
}
当我运行时,我会在ofy()行获取java.lang.ExceptionInInitializerError。 我忘记做了什么?
这是现在的枚举
package com.hmt1.entities;
import com.googlecode.objectify.annotation.Embed;
import com.googlecode.objectify.annotation.Entity;
@Embed
public enum countryCode {US,CANADA,MEXICO;
countryCode(){
}
}
这是堆栈跟踪
java.lang.ExceptionInInitializerError
at com.hmt1.objectify.UserOperations.isEmailInUse(UserOperations.java:66)
at com.hmt1.datahandling.SignupPageDataHandling.isemailInUse(SignupPageDataHandling.java:15)
at com.hmt1.controller.SignupController.selection(SignupController.java:71)
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.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:827)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801)
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.googlecode.objectify.cache.AsyncCacheFilter.doFilter(AsyncCacheFilter.java:59)
at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:49)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:383)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.IllegalStateException: Unable to construct an instance of com.hmt1.entities.countryCode; perhaps it has no suitable constructor?
at com.googlecode.objectify.impl.translate.ClassTranslator.<init>(ClassTranslator.java:44)
at com.googlecode.objectify.impl.translate.EmbedClassTranslatorFactory.create(EmbedClassTranslatorFactory.java:43)
at com.googlecode.objectify.impl.translate.TranslatorRegistry.create(TranslatorRegistry.java:91)
at com.googlecode.objectify.impl.translate.ClassTranslator.<init>(ClassTranslator.java:49)
at com.googlecode.objectify.impl.translate.EntityClassTranslator.<init>(EntityClassTranslator.java:46)
at com.googlecode.objectify.impl.Transmog.<init>(Transmog.java:49)
at com.googlecode.objectify.impl.ConcreteEntityMetadata.<init>(ConcreteEntityMetadata.java:58)
at com.googlecode.objectify.impl.Registrar.register(Registrar.java:74)
at com.googlecode.objectify.ObjectifyFactory.register(ObjectifyFactory.java:177)
at com.hmt1.objectify.OfyService.<clinit>(OfyService.java:11)
... 57 more
Caused by: java.lang.IllegalStateException: com.hmt1.entities.countryCode must have a no-arg constructor
at com.googlecode.objectify.impl.TypeUtils.getNoArgConstructor(TypeUtils.java:52)
at com.googlecode.objectify.ObjectifyFactory.construct(ObjectifyFactory.java:78)
at com.googlecode.objectify.impl.translate.ClassTranslator.<init>(ClassTranslator.java:42)
... 66 more
Caused by: java.lang.NoSuchMethodException: com.hmt1.entities.countryCode.<init>()
at java.lang.Class.getConstructor0(Class.java:2715)
at java.lang.Class.getDeclaredConstructor(Class.java:1987)
at com.googlecode.objectify.impl.TypeUtils.getNoArgConstructor(TypeUtils.java:43)
... 68 more
答案 0 :(得分:2)
我不相信枚举需要@Embed符号。