`
xiejin2008
  • 浏览: 123693 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Hibernate,Ext ,Json ,Strut2整合常见错误及解决办法

    博客分类:
  • J2EE
阅读更多

 

 对Hibernate和Ext,Strut2综合开发经验不多。这次算是第一次,遇到了很多问题,每遇到一个问题,都把他记录起来,简单零散的整理啦一下.还是

1、======================================================================================
使用MyEclipse创建JavaEE5.0的Web项目,在使用Hibernate3.5.1的注解功能时出现错误

java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z 。
我程序出现找个错误,主要是在建立关系之后,如果实体,没有通过注解建立关系,就不会出现错误。

解决办法:删除对Java EE 5 Libraries的使用。

问题原因:javaee.jar中的部分类与hibernate-jpa-2.0-api-1.0.0.Final.jar存在版本冲突。
但是如果删除了Java EE 5 Libraries,Web的Servelt又使用不了啦.
后面还是降低hibernate的版本为3.3
请高手,指教指教找个问题。


2、======================================================================================

Duplicate class/entity mapping
Could not parse configuration: /hibernate.cfg

Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping

Caused by: org.dom4j.DocumentException: FWK005 parse may not be called while pa
sing. Nested exception: FWK005 parse may not be called while parsing.

这些错误的解决方法:

总结:
网上搜索的答案:HibernateSessionFactory 中 getSession() 方法加一个 synchronized 就可以实现.
最终解决之后,还是发现,实体注解配置发生了错误,自己检查注解关系配置。

3、===============================================================================================================

复合主键. 不错的文章.
http://taeky.iteye.com/blog/553220
http://fpjason.iteye.com/blog/544088
这边文字也非常详细:
http://www.ll19.com/bb/topic/109#

4、=========================================================================================================
Oracle里面,创建一个序列
 create sequence hibernate_sequence

 minvalue 1
 maxvalue 999999999
 start with 1
 increment by 1
 cache 20
 cycle;

Oracle里面自动增长主键.

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Integer           ID               ;
    private String            NAME             = "";
    private String            PATHNAME         = "";

5、==================================================================================================================

项目使用hibernate 并使用annotation进行对象映射,开始时提示如下:

Error:org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping class="com.zitong.beans.User"/ >

解决办法:

在hibernatefactory配置文件中,不要用Configuration()用AnnotationConfiguration() 此错误解决!

==============================================================================================================================
异常:oracle.jdbc.driver.OracleDatabaseMetaData.supportsGetGeneratedKeys
换一个驱动解决这个问题,推荐使用classes12.jar
java.lang.AbstractMethodError: oracle.jdbc.driver.OracleDatabaseMetaData.supportsGetGeneratedKeys()Z
 at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:123)
 at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
 at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
 at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
 at com.dao.sessionfactory.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:32)
 at com.dao.CommDao.addObject(CommDao.java:39)
 at com.dao.MeasCodeDao.addMeasCode(MeasCodeDao.java:20)
 at com.service.MeasCodeService.addMeaCode(MeasCodeService.java:16)
 at com.test.MeascodeTest.testAddMeaCode(MeascodeTest.java:18)
 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 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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
 at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
 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)

======================================================================================================

6、many to one 配置终于成功啦
非常感谢这篇文章:
http://topmanopensource.iteye.com/blog/532217
它里面值得注意的好东西是:
"(1)在乘客表中order和orderId,同时映射一张表的时候,必须设置insertable = false, updatable = false否则将报错,order对象必须设置inserte = false, update = false."
"(2)在关联的订单中乘客发生变化时必须将关联的Id设置为null.否则数据库中的乘客的信息不会发生变化."

7、========================================================================================================

使用json-lib的转换hibernate查询出来的list对象集合的时候需要注意的地方.
很多时候数据表都有外键表的,当用hibernate查询结果集时,其关联的对象集也一起来,所以会造成转换JSON发生错误;

以下是一段查询 城市表 的,其关联的主键表是 省份名表,
以下是方法里的代码,需要 import net.sf.json.*;

List list1=new hi.TCityDAO().findAll();
  List li=new ArrayList();//用于装入用来转成JSON的List
  for (Iterator iterator = list1.iterator(); iterator.hasNext();) {
   TCity object = (TCity) iterator.next();
   object.setTProvince(null); //将省份表的对象设为空,不然会出错,出错的原因也在此
   li.add(object);
  }

//这个地方要注意,如果是javabean对象时要用 JSONObject json=JSONObject.fromObject(objece);
  JSONArray json=JSONArray.fromObject(li);  

  System.out.println(json.toString()); //最后输出的JSON字符串

8、==============================================================================================================
下列异常>>>>
2010-4-30 16:06:57 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
严重: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
在数据库中,如果设置了约束关系,那么一定要允许级联删除,否则,你在执行删除时会抛出异常。
010-4-30 16:06:57 org.hibernate.util.JDBCExceptionReporter logExceptions
警告: SQL Error: 2292, SQLState: 23000
2010-4-30 16:06:57 org.hibernate.util.JDBCExceptionReporter logExceptions
严重: ORA-02292: 违反完整约束条件 (CIM.FK_PSR_MEASUREMENT) - 已找到子记录

2010-4-30 16:06:57 org.hibernate.util.JDBCExceptionReporter logExceptions
警告: SQL Error: 2292, SQLState: 23000
2010-4-30 16:06:57 org.hibernate.util.JDBCExceptionReporter logExceptions
严重: ORA-02292: 违反完整约束条件 (CIM.FK_PSR_MEASUREMENT) - 已找到子记录

2010-4-30 16:06:57 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
严重: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
 at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
 at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
 at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:172)
 at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
 at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
 at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
 at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
 at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
 at com.ydtf.lcj.lcjpt.dao.core.CommDao.deleteObject(CommDao.java:64)
 at com.ydtf.lcj.lcjpt.dao.core.PowerSystemResourceDao.deletePowerSystemResource(PowerSystemResourceDao.java:30)
 at com.ydtf.lcj.lcjpt.service.core.PowerSystemResourceService.deletePowerSystemResource(PowerSystemResourceService.java:27)
 at com.ydtf.lcj.lcjpt.action.sys.PowerSystemResourceAction.del(PowerSystemResourceAction.java:81)
 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.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
 at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
 at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
 at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
 at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
 at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
 at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
 at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
 at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
 at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
 at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
 at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3592)
 at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
 at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
 at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
 at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
 at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
 at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
 at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: java.sql.BatchUpdateException: ORA-02292: 违反完整约束条件 (CIM.FK_PSR_MEASUREMENT) - 已找到子记录
)

问题的关键在如下两点:

1.       数据库中要允许数据表的级联删除

2.       在映射文件中要将级联删除配置正确

主要是   数据库中要允许数据表的级联删除   千万不能忘记  
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/kangojian/archive/2008/08/21/2808001.aspx
===========.>>>>
但是后来我测试后,
如果数据库里面建立表之间的关系,但是没有建立级联删除,修改等。
我也同样可以根据"一"方,同时删除“多”方的数据。

 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY,mappedBy="meascode")
    private Set<Measurement>  Measurements;
   
Hibernate: delete from CIM.MEASUREMENT where ID=? and MEASCODE=?
Hibernate: delete from CIM.MEASUREMENT where ID=? and MEASCODE=?
Hibernate: delete from CIM.MEASUREMENT where ID=? and MEASCODE=?
Hibernate: delete from CIM.POWERSYSTEMRESOURCE where ID=?
确实是成功啦,删除成功的概率很大.
删除失败的几率很小很小.
但是我可以偶然到一次 ,又重新报上面的异常(如果没有建立数据库的级联的话).
如果又等上以两分钟,重新刷新页面,惊奇的发现又可以删除啦,真是怪怪..,请高手指教。

9、==============================================================================================================


在运行过程中出现
ClassNotFoundException: org.hibernate.hql.ast.HqlToken 错误weblogic异常退出。
原因:
Hibernate3.0 采用新的基于ANTLR的HQL/SQL查询翻译器,在Hibernate的配置文件中,hibernate.query.factory_class属性用来选择查询翻译器。
(1)选择Hibernate3.0的查询翻译器:
hibernate.query.factory_class= org.hibernate.hql.ast.ASTQueryTranslatorFactory
(2)选择Hibernate2.1的查询翻译器
hibernate.query.factory_class= org.hibernate.hql.classic.ClassicQueryTranslatorFactory
为了使用3.0的批量更新和删除功能,只能选择(1)否则不能解释批量更新的语句,当使用的时候出现了不支持条件输入中文的情况。选择(2)可以支持输入中文,但没法解释批量更新语句了
在hibernate3中需要用到antlr,然而这个包在weblogic.jar中已经包含了antrl类库,就会产生一些类加载的错误,无法找到在war或者ear中的hibernate3.jar。
出现这个错误之后,antlr会调用System.exit(),这样weblogic就会中止服务。
解决方法:
1.是在hibernate.properties文件中增加属性:hibernate.query.factory_class,属性的值是org.hibernate.hql.classic.ClassicQueryTranslatorFactory,这样就可以解决问题了。
但是部分功能会有问题,譬如
但本系在批量删除和更新会有问题,本系统不采用
2.将antlr-2.7.5H3.jar到Weblogic的pre_Classpath :用WinRar或Winzip打开C:\bea\weblogic81\server\lib\weblogic.jar 删除里面的antlr目录, 然后再antlr-2.7.5H3.jar放在weblogic.jar的同一目录(注:替换之后没做做过严格测试,尚不知是否有后遗症)
3. 1、拷贝Hibernate3里带的包antlr-2.7.5H3.jar到%WL_HOME%\server\lib下
2、修改% mydomain% \ startWebLogic.cmd :
在set CLASSPATH之前加上下面一句:
set PRE_CLASSPATH=%WL_HOME%\server\lib\antlr-2.7.5H3.jar;
在set CLASSPATH之后加上下面一句:
set CLASSPATH=%PRE_CLASSPATH%;%CLASSPATH%
一切OK!
具体原因可参照此页:http://dev2dev.bea.com/blog/pmalani/archive/2005/07/configuring_web.html
=====>>
当我执行HQL语句:
select count(*) from MyTest 时候报了以上的错误.
我按照它的方法
在hibernate.cfg.xml文件加了这句话,果然搞定啦.
hibernate.query.factory_class= org.hibernate.hql.classic.ClassicQueryTranslatorFactory


10、==============================================================================================================

   Json转换hiberate查询出来的 List对象集合。
 There is a cycle in the hierarchy! 这个真的是个郁闷的问题 :
Hibernate: select measuremen0_.MEASCODE as MEASCODE2_, measuremen0_.ID as ID2_, measuremen0_.ID as ID5_1_, measuremen0_.MEASCODE as MEASCODE5_1_, measuremen0_.ALIASNAME as ALIASNAME5_1_, measuremen0_.MAXVALUE as MAXVALUE5_1_, measuremen0_.MINVALUE as MINVALUE5_1_, measuremen0_.PATHNAME as PATHNAME5_1_, measuremen0_.POINTNAME as POINTNAME5_1_, powersyste1_.ID as ID6_0_, powersyste1_.ALIASNAME as ALIASNAME6_0_, powersyste1_.DESCRIPTION as DESCRIPT3_6_0_, powersyste1_.ISAVAILABLE as ISAVAILA4_6_0_, powersyste1_.NAME as NAME6_0_, powersyste1_.PATHNAME as PATHNAME6_0_, powersyste1_.PSRTYPE as PSRTYPE6_0_ from CiM.MEASUREMENT measuremen0_ inner join CIM.POWERSYSTEMRESOURCE powersyste1_ on measuremen0_.ID=powersyste1_.ID where measuremen0_.MEASCODE=?
net.sf.json.JSONException: There is a cycle in the hierarchy!
 at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java:73)
 at net.sf.json.JSONObject._fromBean(JSONObject.java:658)
 at net.sf.json.JSONObject.fromObject(JSONObject.java:182)
 at net.sf.json.JSONObject._processValue(JSONObject.java:2426)
 at net.sf.json.JSONObject._setInternal(JSONObject.java:2447)
 at net.sf.json.JSONObject.setValue(JSONObject.java:1189)
 at net.sf.json.JSONObject._fromBean(JSONObject.java:725)
 at net.sf.json.JSONObject.fromObject(JSONObject.java:182)
 at net.sf.json.JSONArray._processValue(JSONArray.java:2294)
 at net.sf.json.JSONArray.processValue(JSONArray.java:2325)
 at net.sf.json.JSONArray.addValue(JSONArray.java:2312)
 at net.sf.json.JSONArray._fromCollection(JSONArray.java:841)
 at net.sf.json.JSONArray.fromObject(JSONArray.java:137)
 at net.sf.json.JSONObject._processValue(JSONObject.java:2402)
 at net.sf.json.JSONObject._setInternal(JSONObject.java:2447)
 at net.sf.json.JSONObject.setValue(JSONObject.java:1189)
 at net.sf.json.JSONObject._fromBean(JSONObject.java:725)
 at net.sf.json.JSONObject.fromObject(JSONObject.java:182)
 at net.sf.json.JSONArray._processValue(JSONArray.java:2294)
 at net.sf.json.JSONArray.processValue(JSONArray.java:2325)
 at net.sf.json.JSONArray.addValue(JSONArray.java:2312)
 at net.sf.json.JSONArray._fromCollection(JSONArray.java:841)
====================================================================================================
当遇到这个问题的时候:
There is a cycle in the hierarchy!
需要将在实体关系一对多中的.
将"一"这方里面的 "多"的Set 集合的属性,生成json的时候过滤。
关键代码:
jsonConfig.setExcludes ( new String[] { "handler", "hibernateLazyInitializer", "measurements", "powerSystemResource" } );
measurements,powerSystemResource。这两个都是set集合的变量。


11、======================================================================================================

Ext.

 

如果一个一对多的关系,在查询多的一方的时候,需要在grid里面显示一方的名称.(原只是引用ID)
当添加,多的一方的时候,gird不会立即查询数据库,需要有一下的设置才能够立即查询数据库.
如果要求保存后,立即查询数据库.
实例:
powerSysResource.setALIASNAME ( powerSysResourceAliasName );
powerSysResource.setDESCRIPTION ( powerSysResourceDescription );
powerSysResource.setISAVAILABLE ( powerSysResourceIsAvailable );
powerSysResource.setNAME ( powerSysResourceName );
powerSysResource.setPATHNAME ( powerSysResourcePathName );
powerSysResource.setIntPsrType ( powerSysResourcePsrType );

powerSysResource.setPsrType ( psrTypeService.getPsrTypeByID ( powerSysResourcePsrType ) ); 映射的时候,添加外键的映射,也添加外键对象的映射,。找个地方需要设置type对象,也要设置typeid.

 

5
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics