Opened 12 years ago
Closed 12 years ago
#1236 closed defect (fixed)
Metadata not being spatially indexed in Oracle database
Reported by: | asedgmen | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | v2.8.1 |
Component: | General | Version: | v2.8.0 |
Keywords: | Oracle spatial | Cc: |
Description
The following error occurs when an ISO 19139 record is created or edited in a GeoNetwork instance using Oracle with spatial indexing in the database (tested against both Oracle 11g Enterprise and XE):
2013-03-06 13:14:55,905 ERROR [geonetwork.datamanager] - The metadata document index with id=1 is corrupt/invalid - ignoring it. Error: Unknown attribute id org.geotools.feature.IllegalAttributeException:Unknown attribute id:null value:null
at org.geotools.feature.simple.SimpleFeatureImpl.setAttribute(SimpleFeatureImpl.java:246) at org.fao.geonet.kernel.search.spatial.SpatialIndexWriter.index(SpatialIndexWriter.java:162) at org.fao.geonet.kernel.search.SearchManager.index(SearchManager.java:686) at org.fao.geonet.kernel.DataManager.indexMetadata(DataManager.java:553) .
The hard coded id attribute name "id" being used in the SpatialIndexWriter class is conflicting with the name of the id column in the Oracle database. Prior to adding a spatial index entry to the database, the underlying Geotools code checks the SPATIALINDEX database table (described in a simple feature schema) for a column name matching the hard coded id attribute. Column names for the SPATIALINDEX table in an Oracle database are presented in upper case in the simple feature schema, i.e, the id column appears as "ID", causing the column name check to fail. This issue does not occur with Postgres/PostGIS databases as column names are presented in lower case.
I looked at trying to force Oracle to use lower case column names (couldn't get it to work), and changing the hard coded id attribute to upper case (breaks spatial indexing in Postgres). I found a solution that worked well was to make use of the "findIdColumn" method provided in the SpatialIndexWriter class, which obtains the name of the id column as presented in the simple feature schema. Substituting the use of the hard coded id value with a value obtained by the "findIdColumn" method resolves the issue - achieved by updating line 162 of org.fao.geonet.kernel.search.spatial.SpatialIndexWriter.java (2.8.0 tag) with the following:
Before
template.setAttribute(_IDS_ATTRIBUTE_NAME, id);
After
template.setAttribute(_idColumn.toString(), id);
Spatial indexing for both Oracle and Postgres databases works with this modification.
Committed fix: dbb361f