彭老师:您好!请教个在jdonframework中关于查询list中 KEY的问题???

05-12-28 javadavid
彭老师:您好!
问题是这样的:
比如我在sqlserver里定义一个表,如:
CREATE TABLE [INFORM] (
[id] [bigint] IDENTITY (1, 1) NOT NULL ,
[content] [nvarchar] (50)
) ON [PRIMARY ]
其中:id列为主键,自增长
在jdon 框架列

model里如下:
public class Inform extends Model {

private Integer id;
private String content;

public Inform() {

}

public Inform(Integer id, String content) {
this.id = id;
this.content = content;
}

// id
public Integer getId() {
return id;
}

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


// content
public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}
}

相应的actionForm里如下:
相应的actionForm顺序项数等同上

相应的listaction里如下:
public Model findModelByKey(HttpServletRequest request, Object key) {
Model model = null;
try {
TestService testService = (TestService) WebAppUtil.getService("testService",
request);
model = testService.getInform( (Integer) key);
} catch (Exception ex) {
logger.error(ex);
}
return model;

}

相应的dao里如下:
public Inform getInform(Integer Id) {
String GET_FIELD = "select * from inform where id = ?";
List queryParams = new ArrayList();
queryParams.add(Id);

KQData ret = null;

try {
List list = pageIteratorSolverOfUser.queryMultiObject(queryParams,
GET_FIELD);
Iterator iter = list.iterator();
if (iter.hasNext()) {
Map map = (Map) iter.next();
ret = new Inform();
ret.setContent((String) map.get("content"));
ret.setId((Integer) map.get("id"));

}
} catch (Exception se) {
}
return ret;
}

public PageIterator getInform(int start, int count) throws Exception {
String GET_ALL_ITEMS_ALLCOUNT = "select count(1) from content ";

String GET_ALL_ITEMS = "select id from content ";

return pageIteratorSolverOfUser.getDatas("", GET_ALL_ITEMS_ALLCOUNT,
GET_ALL_ITEMS, start, count);
}

相应的服务实现里如下:
public Inform getInform(Integer id) {
logger.debug(" get Inform from DAO + JDBC");
return jdbcDao.getInform(id);
}

public PageIterator getAllInforms(int start, int count) {
PageIterator pageIterator = new PageIterator(PageIterator.EMPTY, 0,
false);
try {
pageIterator = jdbcDao.getInforms(start, count);
} catch (Exception ex) {
logger.error(ex);
}
return pageIterator;

}
相应的服务里如下:
public Inform getInform(Integer class_id);
public PageIterator getAllInforms(int start, int count);

相应的jdonframework.xml里如下:
model key="id" class ="com.jdon.dataadmin.model.Inform"
actionForm name="informActionForm"/
handler
service ref="testService"
getMethod name="getInform" /
createMethod name="createInform" /
updateMethod name="updateInform" /
deleteMethod name="deleteInform" /
/service
/handler
/model

问题结果如下:
运行http://localhost:8080/test/informListAction.do
数据库里有数据,而页面无显示
后台错误下;
2005-12-28 12:44:26,906 DEBUG [com.jdon.container.pico.PicoContainerWrapper] lookup: name=targetMetaDefLoader
2005-12-28 12:44:26,906 DEBUG [com.jdon.bussinessproxy.config.TargetMetaDefXmlLoader] metaDefs size:2
2005-12-28 12:44:26,906 DEBUG [com.jdon.controller.service.DefaultServiceFactory] getService found :testService
2005-12-28 12:44:26,906 DEBUG [com.jdon.container.visitor.VisitorFactory] first time get ComponentVisitor for com.jdon.dataadmin.service.TestServicePOJOImpcom.jdon.container.visitor.VisitorFactory
2005-12-28 12:44:26,906 DEBUG [com.jdon.container.visitor.HttpSessionProxyVisitor] valueBound active, sessionId :609EDA7847D62E8BB913C9FABA1586DD
2005-12-28 12:44:26,906 DEBUG [com.jdon.container.visitor.HttpSessionProxyVisitor] valueBound active, componentsboxs size:0
2005-12-28 12:44:26,906 DEBUG [com.jdon.controller.service.DefaultServiceFactory] proxyInstanceFactoryVisitable in action
2005-12-28 12:44:26,906 DEBUG [com.jdon.container.visitor.HttpSessionProxyVisitor] enter HttpSessionProxyVisitor
2005-12-28 12:44:26,906 DEBUG [com.jdon.container.visitor.ComponentOriginalVisitor] ComponentOriginalVisitor visit:proxyInstanceFactoryVisitable
2005-12-28 12:44:26,906 DEBUG [com.jdon.container.pico.PicoContainerWrapper] lookup: name=proxyInstanceFactoryVisitable
2005-12-28 12:44:26,906 DEBUG [com.jdon.bussinessproxy.dyncproxy.ProxyInstanceFactoryVisitable] enter Proxy.newProxyInstance
2005-12-28 12:44:26,906 DEBUG [com.jdon.bussinessproxy.dyncproxy.DynamicProxyWeaving] call method:com.jdon.dataadmin.service.TestService.getAllInform
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.AopClient] enter AOP invoker2 for:com.xbellwfdt.jxt.dataadmin.service.TestServicePOJOImp method:getAllInform
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.joinpoint.AdvisorChainFactory] enter create PointcutAdvisor
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.joinpoint.AdvisorChainFactory] find all service's interceptos size=1
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.joinpoint.AdvisorChainFactory] find pojoService's interceptos size=3
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] method.getName() :getAllInform
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.AopClient] MethodInvocation will proceed ...
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] <-----> enter ProxyMethodInvocation proceed() for -1
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] now call inteceptor : com.jdon.aop.interceptor.CacheInterceptor
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.interceptor.CacheInterceptor] enter cacheInteceptor method:getAllInform
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.interceptor.CacheInterceptor] methodMatchsModelGET: returnClassName = com.jdon.controller.model.PageIterator
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.interceptor.CacheInterceptor] cacheInteceptor don't action, enter next invocation.proceed()
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] <-----> enter ProxyMethodInvocation proceed() for 0
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] now call inteceptor : com.jdon.aop.interceptor.PoolInterceptor
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.interceptor.PoolInterceptor] enter PoolInterceptor
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.interceptor.PoolInterceptor] borrow a object:com.xbellwfdt.jxt.dataadmin.service.TestServicePOJOImp from pool
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] <-----> enter ProxyMethodInvocation proceed() for 1
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] now call inteceptor : com.jdon.aop.interceptor.StatefulInterceptor
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.interceptor.StatefulInterceptor] enter StatefulInterceptor
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.interceptor.StatefulInterceptor] target service is not Stateful: com.xbellwfdt.jxt.dataadmin.service.TestServicePOJOImp StatefulInterceptor unactiive
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] <-----> enter ProxyMethodInvocation proceed() for 2
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] finish call all inteceptors
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] enter method reflection
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] target:com.xbellwfdt.jxt.dataadmin.service.TestServicePOJOImp service's method:getAllKQDatasCon running..
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.ProxyMethodInvocation] it is pojo target service
2005-12-28 12:44:26,906 DEBUG [com.jdon.model.query.PageIteratorSolver] enter getPageIterator ..
2005-12-28 12:44:26,906 DEBUG [com.jdon.controller.cache.CacheManager] <-cache->try to get cache: PageIteratorPageIteratorSolverKEYSselect id from JXT_KQ_DATA where 1=1 order by student_timecard_code desc010
2005-12-28 12:44:26,906 DEBUG [com.jdon.controller.cache.CacheManager] <-cache->got it
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.reflection.MethodInvokerUtil] method invoke successfully
2005-12-28 12:44:26,906 DEBUG [com.jdon.aop.interceptor.PoolInterceptor] realease a object:com.xbellwfdt.jxt.dataadmin.service.TestServicePOJOImp to pool
2005-12-28 12:44:26,906 DEBUG [com.jdon.bussinessproxy.dyncproxy.DynamicProxyWeaving] call method:getAllInform finish!
2005-12-28 12:44:26,906 DEBUG [com.jdon.strutsutil.ModelListAction] getCache from db.
2005-12-28 12:44:26,906 DEBUG [com.jdon.container.pico.PicoContainerWrapper] lookup: name=targetMetaDefLoader
2005-12-28 12:44:26,906 DEBUG [com.jdon.bussinessproxy.config.TargetMetaDefXmlLoader] metaDefs size:2
2005-12-28 12:44:26,906 DEBUG [com.jdon.controller.service.DefaultServiceFactory] getService found :testService
2005-12-28 12:44:26,906 DEBUG [com.jdon.controller.service.DefaultServiceFactory] proxyInstanceFactoryVisitable in action
2005-12-28 12:44:26,906 DEBUG [com.jdon.container.visitor.HttpSessionProxyVisitor] enter HttpSessionProxyVisitor
2005-12-28 12:44:26,906 ERROR [com.xbellwfdt.jxt.dataadmin.web.KQDataListAction] java.lang.ClassCastException
2005-12-28 12:44:26,906 WARN [root] com.jdon.strutsutil.ModelListAction
java.lang.Exception: the model Id=(6) maybe be deleted!
at com.jdon.strutsutil.ModelListAction.fetchModel(ModelListAction.java:203)
at com.jdon.strutsutil.ModelListAction.getModelList(ModelListAction.java:144)
at com.jdon.strutsutil.ModelListAction.execute(ModelListAction.java:85)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:122)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:534)
2005-12-28 12:44:26,906 DEBUG [com.jdon.strutsutil.ModelListAction] listForm 's property: getList size is 0

数据库仅有一条数据:id=6
如果我把数据库里的bigint改为char等字符类型
代码里所有相应的Integer改为String就正常了,但我需要自增长的bigint类型列id。
麻烦彭老师您给多多指教,帮忙解决这个问题,还有
就是如果数据库表里列类型有int等非字符型的,运行后该列及其后面的列就不显示数据等,只有同上述全部改为字符型的,一切才正常。
多谢彭老师帮忙解决一下上述问题。多谢!



banq
2005-12-29 09:35
掌握关键:Model的主键类型和数据表的主键类型是一致的,如int对应Integer,bigint 对应Long。

如果还有问题,不用sqlserver,使用mysql试验看看。