NutzCN Logo
问答 类型转换异常错误,求解
发布于 2267天前 作者 wx_jjn2ia9qvotogktb45bf 2440 次浏览 复制 上一个帖子 下一个帖子
标签: ssdb
//调用
public List<SdoMode> getGeoData(){
        Sql sql = Sqls.create("select * from test_h2");
        Entity<SdoMode> entity = dao().getEntity(SdoMode.class);
        sql.setEntity(entity);
        sql.setCallback(Sqls.callback.entities());
        dao().execute(sql);   //出错处
        List<SdoMode> list = sql.getList(SdoMode.class);
        return list;
    }
//报错
08-Oct-2018 16:35:01.004 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\apache-tomcat-8.0.44\webapps\manager has finished in 994 ms
[WARN ] 2018-10-08 16:35:02,034 org.nutz.dao.impl.entity.AnnotationEntityMaker.make(AnnotationEntityMaker.java:117) - No @Table found, fallback to use table name='sdo_mode' for type 'cn.wizzer.app.cms.modules.models.SdoMode'
[DEBUG] 2018-10-08 16:35:02,228 org.nutz.dao.jdbc.Jdbcs.guessEntityFieldColumnType(Jdbcs.java:881) - take field 'sdoData(oracle.spatial.geometry.JGeometry)'(cn.wizzer.app.cms.modules.models.SdoMode) as VARCHAR(128)
[DEBUG] 2018-10-08 16:35:03,595 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - select * from test_h2
org.nutz.dao.DaoException: java.lang.ClassCastException: com.vividsolutions.jts.geom.LineString cannot be cast to org.locationtech.jts.geom.Geometry
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:140)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:93)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:82)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252)
	at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:236)
	at org.nutz.dao.impl.NutDao.execute(NutDao.java:1013)
	at cn.wizzer.app.templet.modules.service.impl.PopulationServiceImpl.getGeoData(PopulationServiceImpl.java:456)
	at cn.wizzer.app.web.commons.core.Setup.initStatisticsData(Setup.java:1032)
	at cn.wizzer.app.web.commons.core.Setup.init(Setup.java:79)

7 回复

自定义ValueAdapter了?

@wendal
重写get方法

public Object get(ResultSet rs, String colName) throws SQLException {
        //WKT w = new WKT();
        //Geometry q =(Geometry) rs.getObject(colName);
        String rspstr = ((Geometry) rs.getObject(colName)).toString();
        JGeometry geo = null;
        try {
            geo = new WKT().toJGeometry(rspstr.getBytes());
        } catch (GeometryExceptionWithContext geometryExceptionWithContext) {
            geometryExceptionWithContext.printStackTrace();
        }
        return geo;
    }

然后java属性是Geometry? 返回的对象类型是LineString ?

@wendal


实体类中为JGeometry类型 @Column @ColDefine(adaptor=GeoValueAdaptor.class) private JGeometry sdoData;

但是在get方法中,将Geometry转换为JGeometry,相当于通过oracle的api操作JGeometry,进而操作Geometry。

H2中 sdodata的数据类型为Geometry oracle中sdodata的数据类型为JGeometry

getter做手脚??? 这是set的时候报错

是啥类型就啥类型, 要取其他类型就做个额外的getter,别在原属性的getter改

添加回复
请先登陆
回到顶部