- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我得到了上面的解释错误并做了一些研究,发现org.springframework.orm.hibernate4.support.OpenSessionInViewFilter 是解决方案。但它不适用于我的应用程序。
将数据加载到 jqGrid 时发生错误。
Struts2 操作类:
import com.ast.domain.admin.AtDivision;
import com.ast.domain.admin.AtOrganisation;
import com.ast.service.admin.OrganisationBo;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import java.util.ArrayList;
import java.util.List;
public class OraganisationAction extends ActionSupport implements ModelDriven<AtOrganisation> {
private String sidx;
// Search Field
private String searchField;
// The Search String
private String searchString;
// he Search Operation ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
private String searchOper;
// Your Total Pages
private Integer total = 0;
//Your result List
//private List<MyBean> gridModel;
//get how many rows we want to have into the grid - rowNum attribute in the grid
private Integer rows = 5;
//Get the requested page. By default grid sets this to 1.
private Integer page = 0;
// sorting order - asc or desc
private String sord;
private boolean loadonce = false;
private Integer records = 0;
private AtOrganisation org = new AtOrganisation();
private AtDivision div = new AtDivision();
private List<AtOrganisation> gridModel = new ArrayList<AtOrganisation>();
private List<AtOrganisation> temp_gridModel = new ArrayList<AtOrganisation>();
private OrganisationBo orgBo;
private String aoId;
public List<AtOrganisation> getTemp_gridModel() {
return temp_gridModel;
}
public void setTemp_gridModel(List<AtOrganisation> temp_gridModel) {
this.temp_gridModel = temp_gridModel;
}
public Integer getRecords() {
return records;
}
public void setRecords(Integer records) {
this.records = records;
if (this.records > 0 && this.rows > 0) {
this.total = (int) Math.ceil((double) this.records / (double) this.rows);
} else {
this.total = 0;
}
}
public String getSidx() {
return sidx;
}
public void setSidx(String sidx) {
this.sidx = sidx;
}
public String getSearchField() {
return searchField;
}
public void setSearchField(String searchField) {
this.searchField = searchField;
}
public String getSearchString() {
return searchString;
}
public void setSearchString(String searchString) {
this.searchString = searchString;
}
public String getSearchOper() {
return searchOper;
}
public void setSearchOper(String searchOper) {
this.searchOper = searchOper;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getRows() {
return rows;
}
public void setRows(Integer rows) {
this.rows = rows;
}
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public String getSord() {
return sord;
}
public void setSord(String sord) {
this.sord = sord;
}
public boolean isLoadonce() {
return loadonce;
}
public void setLoadonce(boolean loadonce) {
this.loadonce = loadonce;
}
public List<AtOrganisation> getGridModel() {
return gridModel;
}
public void setGridModel(List<AtOrganisation> gridModel) {
this.gridModel = gridModel;
}
public String getAoId() {
return aoId;
}
public void setAoId(String aoId) {
this.aoId = aoId;
}
public void setOrgBo(OrganisationBo orgBo) {
this.orgBo = orgBo;
}
public OrganisationBo getOrgBo() {
return orgBo;
}
public AtDivision getDiv() {
return div;
}
public void setDiv(AtDivision div) {
this.div = div;
}
public AtOrganisation getOrg() {
return org;
}
public void setOrg(AtOrganisation org) {
this.org = org;
}
@Override
public AtOrganisation getModel() {
return org;
}
public String gridaction() {
temp_gridModel = orgBo.showorg();
System.out.println("setRecords : "+temp_gridModel.size());
setRecords(temp_gridModel.size());
int to = (getRows() * getPage());
int from = to - getRows();
if (to > getRecords()) {
to = getRecords();
}
if (loadonce) {
setGridModel(temp_gridModel);
} else {
if (searchString != null && searchOper != null && !searchString.equals("") && !searchOper.equals("")) {
System.out.println("Searching within Database");
if (searchOper.equalsIgnoreCase("cn")) {
// setGridModel(DAO.findbyName(searchString));
}
} else {
System.out.println("Not Searching Anywhere");
//setGridModel(DAO.find(from, to));
System.out.println("dili 4444");
setGridModel(temp_gridModel);
}
}
System.out.println("getRecords() : "+(double) getRecords());
System.out.println("(double) getRows() : "+(double) getRows());
total = (int) Math.ceil((double) getRecords() / (double) getRows());
System.out.println("tot " + total);
System.out.println(gridModel.size());
return "grid";
}
public String add() throws Exception {
orgBo.addOrg(org);
gridaction();
return SUCCESS;
}
public String delete() throws Exception {
orgBo.deleteOrg(org);
gridaction();
return SUCCESS;
}
public String edit() throws Exception {
orgBo.updateOrg(org);
gridaction();
return SUCCESS;
}
}
服务层获取组织方法:
@Override
@Transactional(propagation = Propagation.REQUIRED)
public List showorg() {
return orgDao.showorg();
}
DAO方法:
@Override
public List showorg() {
Session session = sessionfactory.getCurrentSession();
org.hibernate.Query query = session.createQuery("from AtOrganisation");
List list = query.list();
return list;
}
web.xml
:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/SpringConfiguration.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>Open Session in View Filter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Open Session in View Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
struts.xml
:
<interceptors>
<interceptor-stack name="defaultStack">
<interceptor-ref name="params">
<param name="acceptParamNames">
(\\[\\d+\\]\\.)*\\w+((\\.\\w+)|(\\[\\d+\\])|(\\(\\d+\\))|(\\['\\w+'\\])|(\\('\\w+'\\)))*
</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="*orgs" class="com.ast.action.admin.OraganisationAction"
method="{1}">
<interceptor-ref name="defaultStack"/>
<result name="grid" type="json"></result>
</action>
错误堆栈:
21:56:35,526 ERROR [org.apache.struts2.dispatcher.Dispatcher] (http-/127.0.0.1:8080-1) Exception occurred during processing request: org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.ast.domain.admin.AtOrganisation.atDivisions, could not initialize proxy - no Session: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.ast.domain.admin.AtOrganisation.atDivisions, could not initialize proxy - no Session
at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:246) [struts2-json-plugin-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178) [struts2-json-plugin-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168) [struts2-json-plugin-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134) [struts2-json-plugin-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102) [struts2-json-plugin-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116) [struts2-json-plugin-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:202) [struts2-json-plugin-2.3.16.3.jar:2.3.16.3]
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:176) [struts2-json-plugin-2.3.16.3.jar:2.3.16.3]
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371) [xwork-core-2.3.16.jar:2.3.16]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275) [xwork-core-2.3.16.jar:2.3.16]
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249) [xwork-core-2.3.16.jar:2.3.16]
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) [xwork-core-2.3.16.jar:2.3.16]
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) [xwork-core-2.3.16.jar:2.3.16]
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) [struts2-core-2.3.16.jar:2.3.16]
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:562) [struts2-core-2.3.16.jar:2.3.16]
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) [struts2-core-2.3.16.jar:2.3.16]
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99) [struts2-core-2.3.16.jar:2.3.16]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_40]
Caused by: org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.ast.domain.admin.AtOrganisation.atDivisions, could not initialize proxy - no Session
请提供一些方法来解决这个问题。
最佳答案
您应该仅将那些想要在网格中显示的属性序列化为 JSON。它可以通过不同的方式来实现:
1) 将要使用参数序列化的属性限制为 json 结果
@Result(type = "json", params = {
"includeProperties", "gridModel\\[\\d+\\]\\.id, gridModel\\[\\d+\\]\\.name, total, records, rows, page, sidx, searchField, searchString",
"excludeNullProperties", "true"
})
2) 通过 json 注释排除属性。
@JSON(serialize = false, deserialize = false) // this prevents from output name field values
如果您使用了“在 View 中打开 session ”过滤器,那么它可以加载这些属性并按需初始化它们,即在序列化期间。因为当您的操作返回 JSON 结果时,hibernate session 仍然保持打开状态。当结果返回时,Struts2 执行它。此时 session 应该开放。为了实现这一点,您应该配置过滤器链的顺序。如果 Open Session In View 过滤器处于第一顺序,则可以在执行 Struts2 结果后关闭 session 。
<filter>
<filter-name>Open Session in View Filter</filter-name>
<filter-class>
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>Open Session in View Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
关于Spring、Struts 2、Hibernate 应用程序中的 JSONException : org. hibernate.LazyInitializationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23982290/
我有 7 个协议(protocol),我想在网站上显示。但该网站仅显示 4 个协议(protocol),尽管 JSON 文件中有 7 个协议(protocol)。我决定用调试器检查一下,它通过了 4
我在此代码中遇到 JSON 异常: JSONObject jObject = new JSONObject(JSONString); pontosUsuario.setIdUsuari
我创建了以下价格和移动型号名称的 json 数组。此数据是从表名称为“products”的 wamp phpmyadmin 服务器读取的: { "products": [
我正在从 linkedHashMap 获取 JSON 值 LinkedHashMap lst = JsonPath.parse(json).read("$.projects[0].issuetypes
我正在尝试使用来自 Guardian API 的 JSON 对象。 这是我调用的结果: https://pastebin.com/wqggLEeZ 这是我的代码 JSONObject root = n
我正在尝试从数据库中检索数据。我向此 PHP 文件发送请求: $code, "message"=>$message); echo json_encode($err); }
JSONObject login = new JSONObject(); login.put("Key1", "Value1"); 我只是想用键值对创建一个简单的 JSON 对象。我收到此异常“Unh
我试图解析下面的 json 并在第 150 行(在代码中标记)捕获了 JSONException,但我无法弄清楚为什么会发生。目标是找到特定包的测试列表并将其存储在 arraylist 中。 当我将
我在解析 JSON 时遇到很多问题,其中一个值具有空值。 { "available_from" : "2012-11-05T00:00:00Z", "available_to" : "2012-11-
我有一个带有一些 spring crud 存储库的经典 spring web 应用程序。 我正在尝试以经典的 Angular 形式保存我的实体,但我随机收到此错误: .w.s.m.s.DefaultH
我正在尝试将字符串转换为 JSONObject。这是我的代码: JSONObject obj = new JSONObject(str); Vehicle.feature 文件包含: Scen
@Override protected Integer doInBackground(Void... params) { String readMyJSON = rea
我想解析一些从网上下载的 JSONArray 中的 json。我认为这很简单,但无法让它发挥作用。 看来问题出在 JSON 格式上。我尝试了不同的方法修复它,但没有任何帮助。 我用这种方法下载字符串:
我收到以下错误: JSONException: No value for error 在 Android Studio 中的我的日志(查看日志截图的链接: /image/45eeF.png )上,它说
它可以很好地从数据库读取和写入,但会给出 JSONException 错误。任何帮助将不胜感激! 谢谢 最佳答案 此错误发生在 JSONObject 的 getter 函数中,这意味着您尝试使用 JS
我想从此链接获取json数据:link &这是我的代码: private static String url = "https://graph.facebook.com/fql?q=SELECT%20
描述:在 OnRespose 方法中,我可以在日志中看到从 froecast.io 接收的数据,但是当我传递“response.body().string()”时,即来自 Forecast.io 的数
我正在尝试从此网址中抓取书名:http://api.nytimes.com/svc/books/v2/lists/2010-10-01/trade-fiction-paperback?api-key=
我一直在尝试在 android studio 中为我的应用程序创建一个登录系统,但我不断收到此错误 org.json.JSONException: Value Connection of type j
我有一个 iOS 应用程序和一个 Android 应用程序,可以使用 RESTFul Web 服务。 当我向服务进行查询时,我得到一个像这样返回的 JSON 对象。 [ { "
我是一名优秀的程序员,十分优秀!