优雅Java编程 之 使用Hibernate存储Oracle Spatial对象

[size=large][align=center]使用Hibernate存储Oracle Spatial对象[/align][/size]

在hibernate.cfg.xml文件中做如下设置:
<!– dialect for Oracle 10G Spatial –>
<property name=”dialect”>com.navsys.spatial.OracleSpatialDialect</property>

在对应java bean的ORM文件中,设置属性的java类型为com.navsys.spatial.JGeometryType

<property name=”geoloc” column=”GEOLOC” type=”com.navsys.spatial.JGeometryType”></property>

以下是使用hibernate保存Geometry的java 代码样例

  
LBSBusLine busLine = new LBSBusLine();
........
........
//Geometry的坐标数组
double coords = .....
//构造oracle.spatial.geometry.JGeometry对象
JGeometry geometry = null;
geometry = JGeometry.createLinearLineString(coords,2,8307);//保存成为一种线型
//将oracle.spatial.geometry.JGeometry对象封装成 com.navsys.spatial.JGeometryType对象
JGeometryType gotmetryType = new JGeometryType(geometry);
busLine.setGeoloc(gotmetryType);
.........
.........
//通过Hibernate Session保存bean
session.save(busLine);

由于com.navsys.spatial.JGeometryType是对oracle.spatial.geometry.JGeometry对象使用装饰模式实现了彻底封装,因此,在读取JGeometry属性的操作中,直接使用bean的GET方法即可获得 com.navsys.spatial.JGeometryType型的信息就可以了。

以下附上几个需要的jar包:
(PS:上传jar文件不成功,只好将文件名改为.zip,请各位下载后手动将文件名改回.jar)
转载自:https://blog.csdn.net/linliangyi2006/article/details/83219912

You may also like...

退出移动版