Question

In my current application i have a service which uses a saxparser to read some xml. In saxparser i try to store a new objectto the database but i get the following error:

ERROR util.JDBCExceptionReporter  - Connection is read-only. Queries leading to data  modification are not allowed

My Service looks like so:

@Transactional
class SchedulingService {

   def printIets() {
    LessonParser par = new LessonParser()
    print "de service macheert ier e trut"

    par.parse(["src/data/tweede/"])

   }
}

The parser:

class LessonParser {

public void parse(baseFileLocations){
     ....
      SAXParserFactory factory = SAXParserFactory.newInstance();
      SAXParser saxParser = factory.newSAXParser();

      LessonHandler handler = new LessonHandler()             
      saxParser.parse(is, handler);

     ...

    }
}

And finally the handler where the attempt to save something to the database is made

class LessonHandler extends DefaultHandler{
    @Override
public void endElement(String uri, String localName, String qName) throws SAXException {

    if (qName.equalsIgnoreCase("TTSession")) {
        //voorlopig enkel hoorcolleges
        if (parse && this.courseType == CourseType.HC) {
            Course course = new Course (name:this.name , info:this.info,courseType:this.courseType,creator:this.creator)
            course.save()

        }
    }
}
}

The error occurs when i try to save a course in the above handler. Also i'm using a mysql database

No correct solution

OTHER TIPS

I had connected the service to a restful api, i forgot an @transactional definition there. Adding it did the trick

Thanks for sharing.

the service got a "@Transactional(readOnly = true)" definition. So all the methods will be read only.

If you want to do some modification, you need to add "@Transactional" before the method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top