分类目录归档:JAVA

JAVA

case by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z

使用hibernate-distribution-3.6.9.Final-dist包时出现如下错误:

java.lang.NoSuchMethodError: javax.persistence.OneToOne.orphanRemoval()Z
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1641)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:1002)
at org.hibernate.tool.hbm2ddl.SchemaExport.(SchemaExport.java:130)
at org.hibernate.tool.hbm2ddl.SchemaExport.(SchemaExport.java:92)
at com.cloudcode.tk.test.HibernateORMappingTest.testSchemaExport(HibernateORMappingTest.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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)

1解决办法:hibernate-jpa-2.0-api-1.0.1.Final.jar 与ejb3-persistence.jar 有冲突,可以把ejb3-persistence删除,


java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter

org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:108)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:133)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:322)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:485)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:133)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:286)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
at com.cloudcode.tk.junit.StudentTest.test(StudentTest.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:105)
… 31 more
Caused by: java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter
at org.hibernate.bytecode.javassist.BytecodeProviderImpl.getProxyFactoryFactory(BytecodeProviderImpl.java:49)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactoryInternal(PojoEntityTuplizer.java:205)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:183)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:167)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:77)
… 36 more
Caused by: java.lang.ClassNotFoundException: javassist.util.proxy.MethodFilter
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 41 more

 把包javassist-3.12.0.GA.jar加入

error at ::0 can’t find referenced pointcut解决方法

在项目中遇到 error at ::0 can't find referenced pointcut 的解决方法
具体错误如下:
 Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut addHanderat org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:315)at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:206)at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:193)at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:174)at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:195)at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:250)at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:284)at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:113)at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:85)at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:66)at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:362)at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:325)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:361)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1344)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)... 14 more
 出现error at ::0 can't find referenced pointcut...这样的错误原因是:如果你用的JDK版本是1.6的话,而引用的aspectjrt.jar是spring-2.0中包含的jar包的情况下就会报这样的错误。 

解决的办法就是下载最新的aspectjrt的jar包即可aspectj-1.6.6.jar 

下载地址http://www.eclipse.org/aspectj/downloads.php

Java REST框架一览

目前宣称支持REST的Java框架包括以下这些: 
Restlet(http://www.restlet.org/) 
Cetia4() 
Apache Axis2(http://http://ws.apache.org/axis2/) 
sqlREST(http://sqlrest.sourceforge.net/) 
REST-art(http://rest-art.sourceforge.net/) 

以下对这些框架进行了较为全面的分析。 

Restlet,最新版本1.0.1 
特点:完全抛弃了Servlet API,作为替代,自己实现了一套API。能够支持复杂的REST架构设计。 
缺点: 
1. 虽然也可以运行于Web容器中,但是难以利用Servlet和JSP等资源。因为需要另外学习一套API和概念,学习成本比较高。 
2. 完全不支持服务器端的HTTP Session,强制完全基于无状态服务器模型来做开发。对于基于浏览器的应用来说,开发难度较高。 
3. 自身没有包括与Spring的集成,可以使用第三方代码与Spring集成,集成难度较大。 
4. 文档不是很丰富,大多比较简短,很多时候需要自己去读代码,或者到其wiki上去查找。 
5. 没有内建的国际化支持。 
优点: 
1. 有内建的HTTP认证机制,不需要另外开发安全机制。 
2. 灵活性较高,支持更多的REST概念,支持透明的内容协商,适合于开发更加强大的REST组件(不限于服务器端应用)。 
3. 零配置文件,全部配置通过代码来完成。 

相关资源: 
功能列表:http://www.restlet.org/about/features
简介:http://www.restlet.org/about/introduction
教程:http://www.restlet.org/documentation/1.0/tutorial
FAQ:http://www.restlet.org/about/faq

Cetia4,最新版本1.0 
特点:基于Servlet API开发,可以运行于所有的Web容器中。 
优点: 
1. 可以充分利用Servlet API和JSP等资源,需要额外学习的概念较少,学习成本较低。 
2. 对于传统的Web应用,可以使用服务器端HTTP Session;对于Web服务类应用,不使用HTTP Session,基于无状态服务器模型做开发。 
3. 自身包括了对于Web MVC的支持,熟悉Web MVC框架的开发者很容易理解。还内建了参数映射、参数验证等等传统Web MVC框架所支持的功能。 
4. 内建了自己特有的导航对象栈的概念,对于支持传统的Web应用的开发(基于浏览器的导航)非常有帮助。 
5. 提供了JSP标签库,对于传统的基于HTML表单的Web开发非常有帮助。 
6. 支持与SiteMesh相配合,由SiteMesh来支持页面布局的重用。 
7. 内建有与Spring的集成,集成起来非常容易。 
8. 配置文件完全基于标准的web.xml,不需要额外的配置文件。大量使用默认配置,一般情况下足以满足常见的需求。 
9. 拥有很好的文档。 
10. 有内建的国际化支持。 
缺点: 
1. 没有内建的HTTP认证机制,需要自行开发安全机制。 
2. 对于内容协商的支持比较弱,仅支持HTML和XML格式的表现。需要加以扩展才能支持其他格式的表现。 

相关资源: 
教程:

Axis2,最新版本1.2 
特点:同时支持SOAP和REST风格的Web Service。 
缺点: 
1. 仅仅支持GET与POST方法。 
2. 仅仅是以REST风格暴露出Web服务,数据格式仍然是包含SOAP封装的XML,不能使用更加有效的格式。 
3. 只支持同步的调用方式。 
4. 仅仅提供了以SOAP方式暴露Web服务的最小化的支持,不支持全面的REST架构设计。 

相关资源: 
简介:http://ws.apache.org/axis2/1_2/rest-ws.html

sqlREST,最新版本0.3.1 
特点: 
1. 为任何可以通过JDBC访问的数据库提供Web服务访问接口,自动将REST风格的HTTP请求转换为相应的数据库SQL语句,并将数据库中的记录编码为XML格式传给客户端。是REST风格的HTTP请求到数据库中的数据的直接映射。 
2. 基于Servlet API开发。 
缺点: 
1. 因为是REST风格的HTTP请求到SQL语句的直接映射,因此强制使用以SQL和关系数据库为中心的数据建模设计方法,不支持面向对象的设计。灵活性很低,难以实现较为复杂的业务逻辑。 
2. 因为资源的定义仅限于数据库的表,难以实现更高层次的抽象,必然会导致非常细粒度的API。应用的性能和可伸缩性都难以保证。 

相关资源: 
教程:http://sqlrest.sourceforge.net/5-minutes-guide.htm

REST-art,最新版本0.2 
特点:一个旨在替换复杂的SOAP框架的REST框架,用来作为替代SOAP方便地发布Web服务的工具。不是基于Servlet API开发。 
缺点: 
1. 目前尚处于刚刚起步的阶段,功能非常少。 
2. 不是基于Servlet API,带来了额外的学习成本。 

相关资源: 

教程:http://sourceforge.net/docman/index.php?group_id=175132

来自:http://www.iteye.com/topic/85928