java long转换string,java.lang.Long不能转换为java.lang.String

I need to iterate a List in a jsp. This is how I obtain the list:

(when I commented it, the page loaded just fine).

List pjList = null;

StringBuffer ejbQuery = new StringBuffer();

EntityManagerFactory emf = Persistence.createEntityManagerFactory("myPersistence");

EntityManager em = emf.createEntityManager();

ejbQuery.append("SELECT e ");

ejbQuery.append("FROM myClass e ");

pjList = em.createQuery(ejbQuery.toString()).getResultList();

for(myClass pj : pjList)

{

%>

}

%>

This is the error I get when running it in google appengine. locally it runs fine.

Uncaught exception from servlet

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String

at org.datanucleus.store.appengine.DatastoreFieldManager.fetchStringField(DatastoreFieldManager.java:188)

at org.datanucleus.state.AbstractStateManager.replacingStringField(AbstractStateManager.java:1180)

at ar.edu.kennedy.proveedores.entities.ProEnteEy.jdoReplaceField(ProEnteEy.java)

at ar.edu.kennedy.proveedores.entities.ProPersonaJuridicaEy.jdoReplaceField(ProPersonaJuridicaEy.java)

at ar.edu.kennedy.proveedores.entities.ProEnteEy.jdoReplaceFields(ProEnteEy.java)

at org.datanucleus.state.JDOStateManagerImpl.replaceFields(JDOStateManagerImpl.java:2772)

at org.datanucleus.state.JDOStateManagerImpl.replaceFields(JDOStateManagerImpl.java:2791)

at org.datanucleus.store.appengine.DatastorePersistenceHandler.fetchObject(DatastorePersistenceHandler.java:443)

at org.datanucleus.store.appengine.query.DatastoreQuery.entityToPojo(DatastoreQuery.java:433)

at org.datanucleus.store.appengine.query.DatastoreQuery.entityToPojo(DatastoreQuery.java:391)

at org.datanucleus.store.appengine.query.DatastoreQuery.access$800(DatastoreQuery.java:97)

at org.datanucleus.store.appengine.query.DatastoreQuery$5.apply(DatastoreQuery.java:515)

at org.datanucleus.store.appengine.query.DatastoreQuery$5.apply(DatastoreQuery.java:507)

at org.datanucleus.store.appengine.query.StreamingQueryResult.resolveNext(StreamingQueryResult.java:137)

at org.datanucleus.store.appengine.query.StreamingQueryResult$1.computeNext(StreamingQueryResult.java:163)

at org.datanucleus.store.appengine.query.AbstractIterator.tryToComputeNext(AbstractIterator.java:132)

at org.datanucleus.store.appengine.query.AbstractIterator.hasNext(AbstractIterator.java:127)

at org.datanucleus.store.appengine.query.StreamingQueryResult$AbstractListIterator.hasNext(StreamingQueryResult.java:229)

at org.apache.jsp.busqueda_jsp._jspService(busqueda_jsp.java:138)

If I use a ListIterator and call hasNext() I get the same error. Help me understand what is happening, how to solve this?

解决方案

It looks like the mapping you have from "myclass" is wrong.

There is a field marked as "String" when in fact it is a "number".

What it seems to happen from the StackTrace is that your value is fetched from the database and then casted to a string.

Since the value is not an string, you get that exception.

Try identifying in your class which "numeric" values are mapped as String and have them fixed. Start one by one until it works.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值