agrosner / DBFlow

A blazing fast, powerful, and very simple ORM android database library that writes database code for you.
MIT License
4.87k stars 598 forks source link

Build failed at OneToManyDefinition class #1545

Closed gerosyab closed 6 years ago

gerosyab commented 6 years ago

DBFlow Version: 4.2.4

Bug or Feature Request: Build Failed with Exception (OneTomManyDefinition)

Description:

I tried to build my application using DB Flow 4.2.4 but failed with Exception at OneToManyDefinition class.

I think I'm not using any kotlin feature with dbflow but log message seems to be related with kotlin.

Error:09:27:06.989 [ERROR] [system.err] error: ==========class com.raizlabs.android.dbflow.processor.definition.OneToManyDefinition (Kotlin reflection is not available) :OneToMany Methods can only have one parameter and that be the DatabaseWrapper.========== 09:27:06.989 [ERROR] [system.err] error: java.lang.Thread.getStackTrace(Thread.java:1556) 09:27:06.989 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.ProcessorManager.logError(ProcessorManager.kt:229) 09:27:06.989 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.definition.OneToManyDefinition.(OneToManyDefinition.kt:106) 09:27:06.989 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.definition.TableDefinition.createColumnDefinitions(TableDefinition.kt:351) 09:27:06.990 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.definition.TableDefinition.prepareForWrite(TableDefinition.kt:226) 09:27:06.990 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.definition.DatabaseDefinition.prepareDefinitions(DatabaseDefinition.kt:116) 09:27:06.991 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.definition.DatabaseDefinition.validateAndPrepareToWrite(DatabaseDefinition.kt:92) 09:27:06.991 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.ProcessorManager.handle(ProcessorManager.kt:294) 09:27:07.148 [ERROR] [system.err] error: ==========class com.raizlabs.android.dbflow.processor.definition.OneToManyDefinition (Kotlin reflection is not available) :OneToMany Methods can only have one parameter and that be the DatabaseWrapper.========== 09:27:07.149 [ERROR] [system.err] error: java.lang.Thread.getStackTrace(Thread.java:1556) 09:27:07.149 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.ProcessorManager.logError(ProcessorManager.kt:229) 09:27:07.149 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.definition.OneToManyDefinition.(OneToManyDefinition.kt:106) 09:27:07.149 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.definition.TableDefinition.createColumnDefinitions(TableDefinition.kt:351) 09:27:07.149 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.definition.TableDefinition.prepareForWrite(TableDefinition.kt:226) 09:27:07.150 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.definition.DatabaseDefinition.prepareDefinitions(DatabaseDefinition.kt:116) 09:27:07.150 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.definition.DatabaseDefinition.validateAndPrepareToWrite(DatabaseDefinition.kt:92) 09:27:07.150 [ERROR] [system.err] error: com.raizlabs.android.dbflow.processor.ProcessorManager.handle(ProcessorManager.kt:294) 09:27:07.150 [ERROR] [system.err] warning: File for type 'com.raizlabs.android.dbflow.config.AppDatabaseAppDatabase_Database' created in the last round will not be subject to annotation processing. 09:27:07.157 [ERROR] [system.err] 18 errors 09:27:07.157 [ERROR] [system.err] 1 warning 09:27:07.204 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 09:27:07.209 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 09:27:07.210 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 09:27:07.210 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] What went wrong: 09:27:07.210 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':app:compileDebugJavaWithJavac'. 09:27:07.210 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Compilation failed; see the compiler error output for details. 09:27:07.213 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 09:27:07.214 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Try: 09:27:07.214 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace. 09:27:07.218 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 09:27:07.218 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org 09:27:07.219 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] 09:27:

07.219 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 16s

Here is my app's build.gradle.

def` dbflow_version = "4.2.4"
dependencies {
    annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
    compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"
    compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}"
}

And this is my model (only with OneToMany methods).

@Table(database = AppDatabase.class)
public class Category extends BaseModel {
    @PrimaryKey(autoincrement = true)
    private long id;

    @Column
    @Unique
    private String name;

    @Column
    private String unit;

    @Column
    private long order;
    ...
    @OneToMany(methods = {OneToMany.Method.ALL}, variableName = "records")
    public List<Record> getRecords() {
        if (records == null || records.isEmpty()) {
            records = SQLite.select()
                    .from(Record.class)
                    .where(Record_Table.category_id.eq(id))
                    .queryList();
        }
        return records;
    }

    @OneToMany(methods = {OneToMany.Method.ALL}, variableName = "records")
    public List<Record> getRecordsOrderByIdAscending() {
        if (records == null || records.isEmpty()) {
            records = SQLite.select()
                    .from(Record.class)
                    .where(Record_Table.category_id.eq(id))
                    .orderBy(Record_Table.id, true)    //ascending
                    .queryList();
        }
        return records;
    }

    @OneToMany(methods = {OneToMany.Method.ALL}, variableName = "records")
    public List<Record> getRecordsOrderByDateAscending() {
        if (records == null || records.isEmpty()) {
            records = SQLite.select()
                    .from(Record.class)
                    .where(Record_Table.category_id.eq(id))
                    .orderBy(Record_Table.date, true)    //ascending
                    .queryList();
        }
        return records;
    }

    @OneToMany(methods = {OneToMany.Method.ALL}, variableName = "records")
    public List<Record> getRecords(Date fromDate, Date toDate) {
            return SQLite.select()
                    .from(Record.class)
                    .where(Record_Table.category_id.eq(id))
                    .and(Record_Table.date.between(fromDate).and(toDate))
                    .queryList();
    }
   ...
}
agrosner commented 6 years ago

Error is pretty self explanatory:

OneToMany Methods can only have one parameter and that be the DatabaseWrapper

you have:

 @OneToMany(methods = {OneToMany.Method.ALL}, variableName = "records")
    public List<Record> getRecords(Date fromDate, Date toDate) {
            return SQLite.select()
                    .from(Record.class)
                    .where(Record_Table.category_id.eq(id))
                    .and(Record_Table.date.between(fromDate).and(toDate))
                    .queryList();
    }

the date parameters are not allowed.

Timothybas commented 4 years ago

==========class com.raizlabs.android.dbflow.processor.definition.OneToManyDefinition (Kotlin reflection is not available) :@OneToMany definition savePermissions Cannot find referenced variable mPermissions .==========