Hello:

I am running geotools 13.0.

I have an application that creates Point shapes. My application then writes these features in a shapefile and then into MySQL.

When I run the code under Windows, everything works perfect: the data is properly stored in MySQL and I can use it without any trouble.

When I run the code under Linux, shapefiles are created, but the data is not written in MySQL and the following exception is thrown:

[CODE]
WARNING: class org.geotools.filter.function.Collection_NearestFunction has name conflict betwee 'null' and 'Collection_Nearest' Exception in thread "main" java.lang.NoSuchFieldError: LINEARIZATION_TOLERANCE
at org.geotools.jdbc.JDBCFeatureReader.init(JDBCFeatureReader.java:211)
at org.geotools.jdbc.JDBCFeatureReader.<init>(JDBCFeatureReader.java:137) at org.geotools.jdbc.JDBCInsertFeatureWriter.<init>(JDBCInsertFeatureWriter.java:43) at org.geotools.jdbc.JDBCFeatureStore.getWriterInternal(JDBCFeatureStore.java:280) at org.geotools.data.store.ContentFeatureStore.getWriter(ContentFeatureStore.java:151) at org.geotools.data.store.ContentFeatureStore.getWriter(ContentFeatureStore.java:122) at org.geotools.data.store.ContentFeatureStore.getWriterAppend(ContentFeatureStore.java:263) at org.geotools.data.store.ContentFeatureStore.addFeatures(ContentFeatureStore.java:242) at com.technip.projects.gis.GISGenerator.writeShapesMySQL(GISGenerator.java:763) at com.technip.projects.gis.GISGenerator.generatePlatforms(GISGenerator.java:416) at com.technip.projects.gis.GISGenerator.createShapefiles(GISGenerator.java:249)
at Machine.run(Machine.java:739)
at Machine.main(Machine.java:329)
[/CODE]

My code:

[CODE]
private void writeShapesMySQL(List<SimpleFeature> features) throws IOException {
    SimpleFeatureType TYPE = null;

    if (!features.isEmpty()) {
        TYPE = features.get(0).getType();

        // Drop the table if exists
        try (Connection con = conf.requestConnection("gis")) {
con.prepareCall("DROP TABLE IF EXISTS " + TYPE.getTypeName() + ";").execute();
        } catch (Exception e) {}
        if (factory == null) {
            initMySQLStore();
        }

SimpleFeatureCollection collection = new ListFeatureCollection(TYPE, features);

        gisDS.createSchema(TYPE);

        Transaction transaction = new DefaultTransaction("create");
        String      typeName    = null;

        for (String s : gisDS.getTypeNames()) {
            if (s.equalsIgnoreCase(TYPE.getTypeName())) {
                typeName = s;
                break;
            }
        }
        if (typeName == null) {
log.error("Cannot find the type " + TYPE.getTypeName() + " in the known types: " + String.valueOf(gisDS.getTypeNames())); throw new IOException("Cannot find type " + TYPE.getTypeName() + " -- in other words, developer sucks.");
        }

SimpleFeatureSource featureSource = gisDS.getFeatureSource(typeName);

        // System.out.println("SHAPE:"+SHAPE_TYPE);
        if (featureSource instanceof SimpleFeatureStore) {
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;

            featureStore.setTransaction(transaction);
            try {
log.info("Adding " + collection.size() + " features into " + TYPE.getTypeName() + " table.");
                featureStore.addFeatures(collection);
                transaction.commit();
            } catch (Exception problem) {
log.error("Cannot create shapes in MySQL for " + TYPE.getTypeName(), problem);
                transaction.rollback();
            } finally {
                transaction.close();
            }
        }
    } else {
        log.warn("Passed empty list to create GIS database.");
    }
}

 private void initMySQLStore() throws IOException {
    factory = new MySQLDataStoreFactory();

    Map conMap = new HashMap();

    conMap.put("dbtype", "mysql");
    conMap.put("host", conf.getDbserver());
    conMap.put("port", "3306");
    conMap.put("database", "gis");
    conMap.put("user", conf.getDbuser());
    conMap.put("passwd", conf.getDbpass());

    gisDS = factory.createDataStore(conMap);

Map<Class<?>, Integer> classMappings = gisDS.getClassToSqlTypeMappings();

    classMappings.put(String.class, new Integer(Types.LONGVARCHAR));
}
[/CODE]


My first hint is that MySQL is case sensitive in Linux, but not in Windows. So I checked the created tables both in Linux and Windows, and none of them has a field with such a name (LINEARIZATION_TOLERANCE).

Any hints?

Help is highly appreciated, I am clueless on what may be happening.

Thanks,


Juan
PS. I have posted this question in StackOverflow also (http://stackoverflow.com/questions/29809724/geotools-13-error-writing-to-mysql-in-linux).

------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to