7 Replies Latest reply on Dec 18, 2012 7:22 AM by Eleni Papadopoulou

    Cannot store entire object in a table using Camel SQL Gateway

    Eleni Papadopoulou Newbie

      Hi

      I'm trying to use the Camel sql binding to insert a Java object into a table. The Java class has only 2 fields (and also the table contains only 2 columns) and looks like this:

       

      public class SOTest {

       

      private String name;

      private String address;

      public SOTest(String name, String address ){

           this.name = name;

           this.address = address;

      }

      public String getName() {

           return name;

      }

      public void setName(String name) {

           this.name = name;

      }

      public String getAddress() {

           return address;

      }

      public void setAddress(String address) {

           this.address = address;

      }

      }

       

      For this object I created a custom converter

       

      @Converter

      public class MyConverter {

       

      @Converter

      public static Iterator toInputStream(SOTest soTest) {

        return new MyPOJOIterator(soTest);

        }

      }

       

      class MyPOJOIterator implements Iterator {

      private int position = 0;

      private SOTest soTest;

       

      MyPOJOIterator(SOTest soTest) {

           this.soTest = soTest;

      }

      @Override

      public Object next() {

           switch (position++) {

           case 0:

                return soTest.getName();

           case 1:

                return soTest.getAddress();

      }

           return null;

      }

      @Override

      public boolean hasNext() {

            return position < 2;

      }

      @Override

      public void remove() {

      // TODO Auto-generated method stub

      }

      }

       

      and also added  META-INF/services/org/apache/camel/TypeConverter with MyConverter class name

       

      Then following the camel-sql-binding quickstart, I have a service with two operations insert and select (attached file ISQLTestService) and you can also find atached the route.xml and the switchyard.xml.

       

      My problem is that when the insert operation is invoked nothing is stored in the database table although no error is printed in the server log. Note that the the  "retrieve" operation works properly. Also, I have performed a test passing just one input value (a String value) in the insert operation and it works properly and the value is inserted in the respective db table. But I can't make it work when I try to store an entire object in a table.

       

      Thank you