论坛首页 海阔天空论坛

google appengine for java 做的BLOG

浏览 11893 次
精华帖 (0) :: 良好帖 (0) :: 灌水帖 (0) :: 隐藏帖 (1)
作者 正文
   发表时间:2009-04-14  
hateeyes 写道
下一站,火星 写道
http://123tizi.appspot.com/  早八年就搞了个blog,没啥意思


早点共享嘛

ls的ls,lz是java 不是python。 早八年可没有这个
0 请登录后投票
   发表时间:2009-04-15  
struts 写道
fc6029585 写道
请教一下..
gae有关数据库的建立(数据库建立,表的创建)?是怎么弄啊??
有没有相关的地址啊?
我google了很久也没找到方法!!


你写好实现类加上注释。他会自动根据annotation生成数据库表的

http://code.google.com/intl/zh-CN/appengine/docs/java/gettingstarted/



我看了下JPA的注解..但是都没有看到那个注解和自动建库,建表有关系.>!!!
0 请登录后投票
   发表时间:2009-04-15  
我试着写了个JPA注解类,,
本地  run as  gae application 的时候报错..

大家帮忙指点下

Missing required argument 'module[s]'
Google Web Toolkit 1.6.4
HostedMode [-noserver] [-port port-number | "auto"] [-whitelist whitelist-string] [-blacklist blacklist-string] [-logLevel level] [-gen dir] [-style style] [-ea] [-server servletContainerLauncher] [-startupUrl url] [-war dir] [-extra dir] [-workDir dir] [-localWorkers count] module[s]

where
  -noserver      Prevents the embedded web server from running
  -port          Specifies the TCP port for the embedded web server (defaults to 8888)
  -whitelist     Allows the user to browse URLs that match the specified regexes (comma or space separated)
  -blacklist     Prevents the user browsing URLs that match the specified regexes (comma or space separated)
  -logLevel      The level of logging detail: ERROR, WARN, INFO, TRACE, DEBUG, SPAM, or ALL
  -gen           The directory into which generated files will be written for review
  -style         Script output style: OBF[USCATED], PRETTY, or DETAILED (defaults to OBF)
  -ea            Debugging: causes the compiled output to check assert statements.
  -server        Specifies a different embedded web server to run (must implement ServletContainerLauncher)
  -startupUrl    Automatically launches the specified URL
  -war           The war directory to write output files into (defaults to war)
  -extra         The directory into which extra, non-deployed files will be written
  -workDir       The compiler work directory (must be writeable; defaults to a system temp dir)
  -localWorkers  Specifies the number of local workers to use when compiling permutations
and
  module[s]      Specifies the name(s) of the module(s) to host

0 请登录后投票
   发表时间:2009-04-15  
fc6029585 写道
我试着写了个JPA注解类,,
本地  run as  gae application 的时候报错..

大家帮忙指点下

Missing required argument 'module[s]'
Google Web Toolkit 1.6.4
HostedMode [-noserver] [-port port-number | "auto"] [-whitelist whitelist-string] [-blacklist blacklist-string] [-logLevel level] [-gen dir] [-style style] [-ea] [-server servletContainerLauncher] [-startupUrl url] [-war dir] [-extra dir] [-workDir dir] [-localWorkers count] module[s]

where
  -noserver      Prevents the embedded web server from running
  -port          Specifies the TCP port for the embedded web server (defaults to 8888)
  -whitelist     Allows the user to browse URLs that match the specified regexes (comma or space separated)
  -blacklist     Prevents the user browsing URLs that match the specified regexes (comma or space separated)
  -logLevel      The level of logging detail: ERROR, WARN, INFO, TRACE, DEBUG, SPAM, or ALL
  -gen           The directory into which generated files will be written for review
  -style         Script output style: OBF[USCATED], PRETTY, or DETAILED (defaults to OBF)
  -ea            Debugging: causes the compiled output to check assert statements.
  -server        Specifies a different embedded web server to run (must implement ServletContainerLauncher)
  -startupUrl    Automatically launches the specified URL
  -war           The war directory to write output files into (defaults to war)
  -extra         The directory into which extra, non-deployed files will be written
  -workDir       The compiler work directory (must be writeable; defaults to a system temp dir)
  -localWorkers  Specifies the number of local workers to use when compiling permutations
and
  module[s]      Specifies the name(s) of the module(s) to host



他会在项目的web-inf下生成appengine-generated目录。里面存的数据信息。
使用jpa需要把meta-inf下的xml文件换成persistence.xml
0 请登录后投票
   发表时间:2009-04-15  
struts 写道
fc6029585 写道
我试着写了个JPA注解类,,
本地  run as  gae application 的时候报错..

大家帮忙指点下

Missing required argument 'module[s]'
Google Web Toolkit 1.6.4
HostedMode [-noserver] [-port port-number | "auto"] [-whitelist whitelist-string] [-blacklist blacklist-string] [-logLevel level] [-gen dir] [-style style] [-ea] [-server servletContainerLauncher] [-startupUrl url] [-war dir] [-extra dir] [-workDir dir] [-localWorkers count] module[s]

where
  -noserver      Prevents the embedded web server from running
  -port          Specifies the TCP port for the embedded web server (defaults to 8888)
  -whitelist     Allows the user to browse URLs that match the specified regexes (comma or space separated)
  -blacklist     Prevents the user browsing URLs that match the specified regexes (comma or space separated)
  -logLevel      The level of logging detail: ERROR, WARN, INFO, TRACE, DEBUG, SPAM, or ALL
  -gen           The directory into which generated files will be written for review
  -style         Script output style: OBF[USCATED], PRETTY, or DETAILED (defaults to OBF)
  -ea            Debugging: causes the compiled output to check assert statements.
  -server        Specifies a different embedded web server to run (must implement ServletContainerLauncher)
  -startupUrl    Automatically launches the specified URL
  -war           The war directory to write output files into (defaults to war)
  -extra         The directory into which extra, non-deployed files will be written
  -workDir       The compiler work directory (must be writeable; defaults to a system temp dir)
  -localWorkers  Specifies the number of local workers to use when compiling permutations
and
  module[s]      Specifies the name(s) of the module(s) to host



他会在项目的web-inf下生成appengine-generated目录。里面存的数据信息。
使用jpa需要把meta-inf下的xml文件换成persistence.xml


谢谢帮助...我还是自己先慢慢测试一下算了!
0 请登录后投票
   发表时间:2009-04-16  
楼主..麻烦你帮我看一下.我找了一天了也不知道哪出了问题..
如果我将自带的jdoexample  copy到eclipse中就可以直接运行了..

@Entity
public class UserInfo {
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	private Long id;
	
	private String userName;  
 
	private String password; 
	
	@Transient
	private String phone;
 
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}
}

保存这个类..eclipse 控制台打印
DataNucleus Enhancer (version 1.1.0) : Enhancement of classes

DataNucleus Enhancer completed with success for 1 classes. Timings : input=125 ms, enhance=47 ms, total=172 ms. Consult the log for full details

请问是不是意思就是 在gae的本地数据库dataNuclus就已经创建了这个类对应的表?


然后我写了个插入数据库的类
public class InsertDB {
	
	public static void main(String[] args) { 
		EntityManager em=EMF.getEntiryManager();
		for(int i=4;i<9;i++){
		UserInfo user1=new UserInfo();
		user1.setUserName("user"+i+i);
		user1.setPassword(i+i+i+i+i+i+i+i+"");
		user1.setPhone(i+i+"");
		em.merge(user1); 
		} 
	}
}

保存的时候打印 
DataNucleus Enhancer (version 1.1.0) : Enhancement of classes

DataNucleus Enhancer completed with success for 0 classes. Timings : input=32 ms, enhance=0 ms, total=32 ms. Consult the log for full details
DataNucleus Enhancer completed and no classes were enhanced. Consult the log for full details


我将   persistence.xml(google jpa 说明的xml直接copy过来的)  copy  到了  META-INFO 下(和jdoconfig.xml 同一个目录)


写了个main方法  和servlet 运行

    EntityManager em=EMF.getEntiryManager() ;
  Query query=em.createQuery("select u from UserInfo u");
  List list=(List)query.getResultList();
  System.out.println(list.size()+"  size");
  for(int i=0;i<list.size();i++){
  UserInfo user=(UserInfo)list.get(i);
  System.out.println(user.getUserName()+"  </br>");
  }
但是都要报错


HTTP ERROR: 500

UserInfo

RequestURI=/eat
Caused by:

javax.persistence.PersistenceException: UserInfo
	at org.datanucleus.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:276)
	at org.datanucleus.jpa.JPAQuery.getResultList(JPAQuery.java:169)
	at fank.eatServlet.doGet(eatServlet.java:20)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
	at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:306)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at org.mortbay.jetty.Server.handle(Server.java:313)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
	at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
Caused by: org.datanucleus.exceptions.ClassNotResolvedException: UserInfo
	at org.datanucleus.util.Imports.resolveClassDeclaration(Imports.java:194)
	at org.datanucleus.query.compiler.JavaQueryCompiler.compileFrom(JavaQueryCompiler.java:209)
	at org.datanucleus.query.compiler.JPQLCompiler.compile(JPQLCompiler.java:72)
	at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:242)
	at org.datanucleus.store.query.Query.executeQuery(Query.java:1430)
	at org.datanucleus.store.query.Query.executeWithMap(Query.java:1367)
	at org.datanucleus.jpa.JPAQuery.getResultList(JPAQuery.java:153)
	... 24 more

Caused by:

UserInfo
org.datanucleus.exceptions.ClassNotResolvedException: UserInfo
	at org.datanucleus.util.Imports.resolveClassDeclaration(Imports.java:194)
	at org.datanucleus.query.compiler.JavaQueryCompiler.compileFrom(JavaQueryCompiler.java:209)
	at org.datanucleus.query.compiler.JPQLCompiler.compile(JPQLCompiler.java:72)
	at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:242)
	at org.datanucleus.store.query.Query.executeQuery(Query.java:1430)
	at org.datanucleus.store.query.Query.executeWithMap(Query.java:1367)
	at org.datanucleus.jpa.JPAQuery.getResultList(JPAQuery.java:153)
	at fank.eatServlet.doGet(eatServlet.java:20)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
	at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:306)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at org.mortbay.jetty.Server.handle(Server.java:313)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
	at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)

Powered by Jetty://

我的测试jpa项目附件发上来了

如果楼主有空请帮我看看..或者是把您的  简易博客 发给我参考下..哈哈





  • eat.rar (3.1 MB)
  • 下载次数: 14
0 请登录后投票
   发表时间:2009-04-16  
fc6029585 写道
楼主..麻烦你帮我看一下.我找了一天了也不知道哪出了问题..
如果我将自带的jdoexample  copy到eclipse中就可以直接运行了..

@Entity
public class UserInfo {
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	private Long id;
	
	private String userName;  
 
	private String password; 
	
	@Transient
	private String phone;
 
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}
}

保存这个类..eclipse 控制台打印
DataNucleus Enhancer (version 1.1.0) : Enhancement of classes

DataNucleus Enhancer completed with success for 1 classes. Timings : input=125 ms, enhance=47 ms, total=172 ms. Consult the log for full details

请问是不是意思就是 在gae的本地数据库dataNuclus就已经创建了这个类对应的表?


然后我写了个插入数据库的类
public class InsertDB {
	
	public static void main(String[] args) { 
		EntityManager em=EMF.getEntiryManager();
		for(int i=4;i<9;i++){
		UserInfo user1=new UserInfo();
		user1.setUserName("user"+i+i);
		user1.setPassword(i+i+i+i+i+i+i+i+"");
		user1.setPhone(i+i+"");
		em.merge(user1); 
		} 
	}
}

保存的时候打印 
DataNucleus Enhancer (version 1.1.0) : Enhancement of classes

DataNucleus Enhancer completed with success for 0 classes. Timings : input=32 ms, enhance=0 ms, total=32 ms. Consult the log for full details
DataNucleus Enhancer completed and no classes were enhanced. Consult the log for full details


我将   persistence.xml(google jpa 说明的xml直接copy过来的)  copy  到了  META-INFO 下(和jdoconfig.xml 同一个目录)


写了个main方法  和servlet 运行

    EntityManager em=EMF.getEntiryManager() ;
  Query query=em.createQuery("select u from UserInfo u");
  List list=(List)query.getResultList();
  System.out.println(list.size()+"  size");
  for(int i=0;i<list.size();i++){
  UserInfo user=(UserInfo)list.get(i);
  System.out.println(user.getUserName()+"  </br>");
  }
但是都要报错


HTTP ERROR: 500

UserInfo

RequestURI=/eat
Caused by:

javax.persistence.PersistenceException: UserInfo
	at org.datanucleus.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:276)
	at org.datanucleus.jpa.JPAQuery.getResultList(JPAQuery.java:169)
	at fank.eatServlet.doGet(eatServlet.java:20)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
	at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:306)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at org.mortbay.jetty.Server.handle(Server.java:313)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
	at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
Caused by: org.datanucleus.exceptions.ClassNotResolvedException: UserInfo
	at org.datanucleus.util.Imports.resolveClassDeclaration(Imports.java:194)
	at org.datanucleus.query.compiler.JavaQueryCompiler.compileFrom(JavaQueryCompiler.java:209)
	at org.datanucleus.query.compiler.JPQLCompiler.compile(JPQLCompiler.java:72)
	at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:242)
	at org.datanucleus.store.query.Query.executeQuery(Query.java:1430)
	at org.datanucleus.store.query.Query.executeWithMap(Query.java:1367)
	at org.datanucleus.jpa.JPAQuery.getResultList(JPAQuery.java:153)
	... 24 more

Caused by:

UserInfo
org.datanucleus.exceptions.ClassNotResolvedException: UserInfo
	at org.datanucleus.util.Imports.resolveClassDeclaration(Imports.java:194)
	at org.datanucleus.query.compiler.JavaQueryCompiler.compileFrom(JavaQueryCompiler.java:209)
	at org.datanucleus.query.compiler.JPQLCompiler.compile(JPQLCompiler.java:72)
	at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:242)
	at org.datanucleus.store.query.Query.executeQuery(Query.java:1430)
	at org.datanucleus.store.query.Query.executeWithMap(Query.java:1367)
	at org.datanucleus.jpa.JPAQuery.getResultList(JPAQuery.java:153)
	at fank.eatServlet.doGet(eatServlet.java:20)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
	at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:306)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at org.mortbay.jetty.Server.handle(Server.java:313)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
	at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)

Powered by Jetty://

我的测试jpa项目附件发上来了

如果楼主有空请帮我看看..或者是把您的  简易博客 发给我参考下..哈哈







1,首先修改UserInfo主键的注释为
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)

2,删除web-inf下appengine-generated
3,查询语句写错了。应该是select from fank.table.create.UserInfo u

我现在在公司。没有那个博客的代码。如果需要的话。晚上传给你qq:256484
  • eat.rar (3.1 MB)
  • 下载次数: 33
0 请登录后投票
   发表时间:2009-04-16  
谢谢!!!struts!!
0 请登录后投票
   发表时间:2009-05-31  
fc6029585 写道
楼主..麻烦你帮我看一下.我找了一天了也不知道哪出了问题..
如果我将自带的jdoexample  copy到eclipse中就可以直接运行了..

@Entity
public class UserInfo {
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	private Long id;
	
	private String userName;  
 
	private String password; 
	
	@Transient
	private String phone;
 
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}
}

保存这个类..eclipse 控制台打印
DataNucleus Enhancer (version 1.1.0) : Enhancement of classes

DataNucleus Enhancer completed with success for 1 classes. Timings : input=125 ms, enhance=47 ms, total=172 ms. Consult the log for full details

请问是不是意思就是 在gae的本地数据库dataNuclus就已经创建了这个类对应的表?


然后我写了个插入数据库的类
public class InsertDB {
	
	public static void main(String[] args) { 
		EntityManager em=EMF.getEntiryManager();
		for(int i=4;i<9;i++){
		UserInfo user1=new UserInfo();
		user1.setUserName("user"+i+i);
		user1.setPassword(i+i+i+i+i+i+i+i+"");
		user1.setPhone(i+i+"");
		em.merge(user1); 
		} 
	}
}

保存的时候打印 
DataNucleus Enhancer (version 1.1.0) : Enhancement of classes

DataNucleus Enhancer completed with success for 0 classes. Timings : input=32 ms, enhance=0 ms, total=32 ms. Consult the log for full details
DataNucleus Enhancer completed and no classes were enhanced. Consult the log for full details


我将   persistence.xml(google jpa 说明的xml直接copy过来的)  copy  到了  META-INFO 下(和jdoconfig.xml 同一个目录)


写了个main方法  和servlet 运行

    EntityManager em=EMF.getEntiryManager() ;
  Query query=em.createQuery("select u from UserInfo u");
  List list=(List)query.getResultList();
  System.out.println(list.size()+"  size");
  for(int i=0;i<list.size();i++){
  UserInfo user=(UserInfo)list.get(i);
  System.out.println(user.getUserName()+"  </br>");
  }
但是都要报错


HTTP ERROR: 500

UserInfo

RequestURI=/eat
Caused by:

javax.persistence.PersistenceException: UserInfo
	at org.datanucleus.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:276)
	at org.datanucleus.jpa.JPAQuery.getResultList(JPAQuery.java:169)
	at fank.eatServlet.doGet(eatServlet.java:20)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
	at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:306)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at org.mortbay.jetty.Server.handle(Server.java:313)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
	at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
Caused by: org.datanucleus.exceptions.ClassNotResolvedException: UserInfo
	at org.datanucleus.util.Imports.resolveClassDeclaration(Imports.java:194)
	at org.datanucleus.query.compiler.JavaQueryCompiler.compileFrom(JavaQueryCompiler.java:209)
	at org.datanucleus.query.compiler.JPQLCompiler.compile(JPQLCompiler.java:72)
	at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:242)
	at org.datanucleus.store.query.Query.executeQuery(Query.java:1430)
	at org.datanucleus.store.query.Query.executeWithMap(Query.java:1367)
	at org.datanucleus.jpa.JPAQuery.getResultList(JPAQuery.java:153)
	... 24 more

Caused by:

UserInfo
org.datanucleus.exceptions.ClassNotResolvedException: UserInfo
	at org.datanucleus.util.Imports.resolveClassDeclaration(Imports.java:194)
	at org.datanucleus.query.compiler.JavaQueryCompiler.compileFrom(JavaQueryCompiler.java:209)
	at org.datanucleus.query.compiler.JPQLCompiler.compile(JPQLCompiler.java:72)
	at org.datanucleus.store.query.AbstractJPQLQuery.compileInternal(AbstractJPQLQuery.java:242)
	at org.datanucleus.store.query.Query.executeQuery(Query.java:1430)
	at org.datanucleus.store.query.Query.executeWithMap(Query.java:1367)
	at org.datanucleus.jpa.JPAQuery.getResultList(JPAQuery.java:153)
	at fank.eatServlet.doGet(eatServlet.java:20)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
	at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
	at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:306)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
	at org.mortbay.jetty.Server.handle(Server.java:313)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
	at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)

Powered by Jetty://

我的测试jpa项目附件发上来了

如果楼主有空请帮我看看..或者是把您的  简易博客 发给我参考下..哈哈







USERINFO那个前面要加包名
被搞死了,原来hib的项目到这很多都不能用
0 请登录后投票
论坛首页 海阔天空版

跳转论坛:
Global site tag (gtag.js) - Google Analytics