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

[3.0.0-beta1]Table is not registered with a Database. Did you forget the @Table annotation? #515

Closed KChernenko closed 8 years ago

KChernenko commented 8 years ago

But I have the folowing structure:

@Database(name = WeatherDB.NAME, version = WeatherDB.VERSION)
public class WeatherDB {

    public static final String NAME = "Weather";

    public static final int VERSION = 1;
}

And table:

@Table(database = WeatherDB.class)
public class WeatherTable extends BaseModel {

    @Column
    @PrimaryKey
    private long dateStamp;
    @Column
    private double dayTemperature;
    @Column
    private double minTemperature;
    @Column
    private double maxTemperature;
    @Column
    private double nightTemperature;
    @Column
    private double eveTemperature;
    @Column
    private double mornTemperature;
    @Column
    private int humidity;
    @Column
    private String description;
    @Column
    private double windSpeed;

   //getters and setters
}

Full stacktrace:

Process: me.bitfrom.weatherapp, PID: 3939
                                                                     com.raizlabs.android.dbflow.structure.InvalidDBConfiguration: Table: me.bitfrom.weatherapp.database.WeatherTable is not registered with a Database. Did you forget the @Table annotation?
                                                                         at com.raizlabs.android.dbflow.config.FlowManager.getDatabaseForTable(FlowManager.java:109)
                                                                         at com.raizlabs.android.dbflow.config.FlowManager.getModelAdapter(FlowManager.java:271)
                                                                         at com.raizlabs.android.dbflow.config.FlowManager.getTableName(FlowManager.java:68)
                                                                         at com.raizlabs.android.dbflow.sql.language.From.<init>(From.java:55)
                                                                         at com.raizlabs.android.dbflow.sql.language.Select.from(Select.java:58)
                                                                         at me.bitfrom.weatherapp.ui.fragments.TodaysWeatherFragment.onViewCreated(TodaysWeatherFragment.java:31)
                                                                         at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:908)
                                                                         at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
                                                                         at android.app.BackStackRecord.run(BackStackRecord.java:834)
                                                                         at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
                                                                         at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
                                                                         at android.os.Handler.handleCallback(Handler.java:739)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                         at android.os.Looper.loop(Looper.java:211)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5389)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at java.lang.reflect.Method.invoke(Method.java:372)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
MaciejCzekanski commented 8 years ago

I have the same problem

KChernenko commented 8 years ago

@MaciejCzekanski are you using Dagger 2 in your project?

MaciejCzekanski commented 8 years ago

@KChernenko Yes, I can't make them both work at the same time. Do you have any solution?

simplysoft commented 8 years ago

Are you using proguard? If so, this config might help (solved the issue in our case)

-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; }
KChernenko commented 8 years ago

@simplysoft unfortunatelly proguard is disabled. I think it doesn't work in our case (mine and @MaciejCzekanski 's) because of Dagger 2.

MaciejCzekanski commented 8 years ago

Yes, I don't use Proguard. I'm not sure what I've changed, but now I get compile-time error, that Dagger's Component class is missing. When I remove @Table annotation then it compiles, but obviously crashes at runtime with error "Table is not registered with a Database".

KChernenko commented 8 years ago

@MaciejCzekanski have the same problem. Lets mark @agrosner here to infrom.

agrosner commented 8 years ago

There are issues with annotation processors and how order can matter. Dagger2 has some issues with that, and unfortunately I do not know of a solution of how to fix that

amugox commented 8 years ago

This same error is almost making me now think of an alternative ORM

amugox commented 8 years ago

Finally it works for me! I had forgotten to add the Application class on the manifest

<application android:name=".App.TotoApp":

MaciejCzekanski commented 8 years ago

@amugox I have Application class referenced in manifest and it doesn't work. Do you also use Dagger 2?

epool commented 8 years ago

I am getting same error using Dagger 2 =/

Ekt0s commented 8 years ago

I'm getting the same error but just on one of my project, with the exact same database configuration, the one working is the android-testing project.

And I'm not using Dagger 2 :-1: :cry:

epool commented 8 years ago

A workaround I am using to face this in my development process is doing Build -> Build Project and then run it again. =/

agrosner commented 8 years ago

are you guys using 2.0.0+ of the Gradle plugin with instant run enabled?

epool commented 8 years ago

Yes, I am using classpath 'com.android.tools.build:gradle:2.0.0-alpha7' with instant run enabled.

agrosner commented 8 years ago

Im 95% sure its an instant run bug.

rogerhu commented 8 years ago

+1 ProGuard rule fixed things for me. I suggest it be added a consumer proguard rule for the library?

-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; }

jesdiart commented 8 years ago

Hi all

We are having the same problem here, in instrumented unit tests. I am using Dagger 1.2.2 and the build tools are version 1.5.0.

I have an abstract test case that injects the dependencias using dagger:

public abstract class FlowTestCase extends InstrumentationTestCase {

    ObjectGraph objectGraph;

    public FlowTestCase() {
        FlowLog.setMinimumLoggingLevel(FlowLog.Level.I);
    }

    protected void setUp(){
        objectGraph = ObjectGraph.create(new AndroidTestModule(getInstrumentation().getContext())).plus(getModules().toArray());
        objectGraph.inject(this);
    }

But I get the error while trying to delete the tables in the setUp in each test:

@RunWith(AndroidJUnit4.class)
public class ExampleTest extends FlowTestCase {

    @Inject
    LocalDataManager localDataManager;

    @Override
    protected List<Object> getModules() {
        return new ArrayList<>();
    }

    @Before
    public void setUp() {
        super.setUp();
        Delete.tables(MyTable.class);
    }

    @After
    public void tearDown() {
        Delete.tables(MyTable.class);
    }

The injected LocalDataManager executes the FlowManager.init(context);

viethoang88 commented 8 years ago

I can confirm that this issue is caused by instant run. I disabled it and it fixed the issue.

chandramohan11mx08 commented 8 years ago

It happens for me. I am not using dagger, proguard is disabled. I am using android annotations and gradle com.android.tools.build:gradle:2.0.0-alpha7.

It is works well when project is rebuild every time before run.

agrosner commented 8 years ago

use 2.0.0-beta2 - they explicitly fixed the issue: http://tools.android.com/recent/androidstudio20beta2availableincanarychannel

Dagger2 and other annotation-processor based libraries and plugins: In 2.x we've been using the new "incremental Java compilation" feature in Gradle, 
but this feature does not work well with annotation processor. 
In beta2, we automatically turn off incremental compilation if a project appears to be using annotation processors through the "android-apt" plugin. 
Manually wired processors will still fail (see https://github.com/google/dagger/issues/298).
prashantwosti commented 8 years ago

EDIT: Unfortunately, this issue still exists in 2.0 Beta 3

agrosner commented 8 years ago

there are a few potential factors associated with why it fails. 1 is gradle plugin for Android. What version are you using of the Android gradle plugin?

iam1492 commented 8 years ago

still exists in 2.0 Beta 4. Issue disappeared when disable Instant Run.

classpath 'com.android.tools.build:gradle:2.0.0-beta4'

iam1492 commented 8 years ago

still not fixed 2.0 Beta 5.

garmax1 commented 8 years ago

Seems was fixed in com.android.tools.build:gradle:2.0.0-beta6

thekalinga commented 8 years ago

Any idea on whether they disabled instant run for any non-compatible apt they find/instant run works seamlessly with dbflow

levibostian commented 8 years ago

Bummer. Instant run fixed the issue for me as well. Too bad as instant run is pretty sweet. Thanks for finding that solution everyone.

TeddyGammel commented 7 years ago

I am seeing this issue in dbflow version 3.1.1. Disabled instant run on my studio the gradle version being used is 2.1.3. Even with 2.0.0-beta6, its not working.

TeddyGammel commented 7 years ago

@agrosner request your help here. Thank you.

hoanv810 commented 7 years ago

@TeddyGammel Please make sure you have initialized FlowConfig in your Application class!

elroid commented 7 years ago

I'm having this problem as well. DaggerApplicationComponent and DaggerConfigPersistentComponent simply aren't getting created properly when I enable DBFlow. Looks like i'll need to go with a different ORM... :-(

agrosner commented 7 years ago

Ensure you dont have any compile issues. also that you didnt muck up one of the other annotation processor dependant libs, as that will cause side effects in other annotation processors. Ensure incremental compilation is not interfering with annotation processing (it should be fixed as of 2.2.2) If your Dagger2 components are not getting generated, its likely its supressing DBFlow issues or you have an error in Dagger2.

elroid commented 7 years ago

Having done some more experimentation, it seems not to be DBFlow at fault, but rather android-apt. As you alluded to, as of the gradle 2.2.x plugin, this lib is deprecated ( https://bitbucket.org/hvisser/android-apt/wiki/Migration ) and dagger fails the generation step when I include it. But when I try to add dbflow's compile directives, i get: Error:(151, 0) Could not find method apt() for arguments [com.github.Raizlabs.DBFlow:dbflow-processor:4.0.0-beta2] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. Any suggestions for working with DBFlow using the newest gradle plugin?