Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error on missing @ManyToOne instead of ClassCastException at runtime #389

Closed
Pear0 opened this issue Jan 3, 2017 · 1 comment
Closed
Assignees

Comments

@Pear0
Copy link

Pear0 commented Jan 3, 2017

I'm fairly new to Requery and I forgot @ManyToOne on my model class.

@Entity
abstract class AbstractFeedNotification {

    @Key
    @Generated
    int id;

    @Column(nullable = false)
    // @ManyToOne
    FeedSubscription feed;
   
   ...
}

It appears that Requery is converting it to a varchar when storing it in the database instead of an id reference, but this is not obvious and it doesn't cause an error until I try to select from the database.

database.select(FeedNotification.class)
                .where(FeedNotification.ID.eq(id))
                .get()
                .first();

Here's the exception thrown:

java.lang.ClassCastException: Cannot cast java.lang.String to com.example.FeedSubscription
                                                                       at java.lang.Class.cast(Class.java:2308)
                                                                       at io.requery.sql.GenericMapping.read(GenericMapping.java:287)
                                                                       at io.requery.sql.EntityReader.fromResult(EntityReader.java:564)
                                                                       at io.requery.sql.EntityResultReader.read(EntityResultReader.java:45)
                                                                       at io.requery.sql.ResultSetIterator.next(ResultSetIterator.java:101)

It would be nice if this caused a compile-time error as it seems like something that can be validated when the model implementations are generated.

My Requery versions:

compile 'io.requery:requery:1.1.0'
compile 'io.requery:requery-android:1.1.0'
apt 'io.requery:requery-processor:1.1.0'
compile 'io.requery:sqlite-android:3.15.1'
@npurushe npurushe self-assigned this Jan 3, 2017
@npurushe
Copy link
Contributor

npurushe commented Jan 3, 2017

Thanks yes it make sense to make that an error, should be included in the next update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants