ActiveJDBC failed to determine Model class name while findFirst but not while insert

744 Views Asked by At

While debugging in eclipse below spring boot application is working fine inserting a record in the table but is not while doing findFirst, giving me: failed to determine Model class name, are you sure models have been instrumented?

Gradle:

plugins {
    (...)
    id 'java'
    id "de.schablinski.activejdbc-gradle-plugin" version "1.2" apply false 
}

(...)

dependencies {

    implementation group: 'org.javalite', name: 'activejdbc', version: '1.4.11'
    implementation group: 'org.javalite', name: 'activejdbc-instrumentation', version: '1.4.11' 

    (...)
}

/** Task: Instrument ActiveJdbc models **/
    task activeJdbcInstrumentation() {
    apply plugin: 'de.schablinski.activejdbc-gradle-plugin'
}

build.dependsOn(activeJdbcInstrumentation) 

Java

Base.open(dataSource);

try {
    TestConJavaLite model = new TestConJavaLite();          
    model.setString("ID", UUID.randomUUID());
    model.setString("Column1", UUID.randomUUID());
    model.setString("Column2", UUID.randomUUID());
    model.setString("Column3", UUID.randomUUID());
    model.setString("Column4", UUID.randomUUID());
    model.setString("Column5", UUID.randomUUID());
    model.setString("Column5", UUID.randomUUID());
    model.setString("Column6", UUID.randomUUID());
    model.setString("Column7", UUID.randomUUID());
    model.setString("Column8", UUID.randomUUID());
    model.setString("Column9", UUID.randomUUID());
    model.insert(); // --> Works fine

    model = model.findFirst("ID = 1"); // --> Gives error
} catch (Exception e) {
    System.out.println(e.getMessage());
}       

if(Base.hasConnection()) {
    Base.close();
}

What I don't understand is why is giving that error just for the findFirst and not for the insert. Any idea?

1

There are 1 best solutions below

4
ipolevoy On

The way Instrumentation works is described here: https://javalite.io/instrumentation

Basically, instrumentation copies byte code of static methods from class Model into your class. The instance methods are untouched. The findFirst() method is static and if you want to use it, you need instrumentation. The insert() is an instance method, and hence does not require instrumentation.