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

Can't use same class name (but in different packages) for entities in ToOne relations #744

Closed
pontusstjerna opened this issue Aug 1, 2019 · 4 comments

Comments

@pontusstjerna
Copy link

commented Aug 1, 2019

  • ObjectBox version: 2.1.0 gradle plugin for android
  • Reproducibility: always

The bug (or error) is encountered when using two different entity classes in ToOne relations, but the classes have the same name, although in different packages.

@Entity
public class Payment {
    ... 
    ToOne<com.example.data.customerorders.PaymentMethod> paymentMethodRelation;
} 
package com.example.data.customerorders;

@Entity
public class PaymentMethod {
    ... 
    @Id
    long id;
}
@Entity
public class CheckoutInfo {
... 
    ToOne<com.example.data.PaymentMethod> paymentMethodRelation;
}
package com.example.data;

@Entity
public class PaymentMethod {
... 
    @Id
    long anotherId;
}

The error is quite weird and is printed at build time:
error: [ObjectBox] Relation target class 'PaymentMethod' defined in class 'Payment' could not be found (is it an @Entity?)

The workaround I found was to simply change one of the PaymentMethod-classes names to for example CustomerOrderPaymentMethod. But this should not be needed since the two classes are distinct; indeed their full names are not PaymentMethod but com.example.data.customerorders.PaymentMethod and com.example.data.PaymentMethod respectively.

Thanks in advance and thanks for a great library!

@greenrobot-team

This comment has been minimized.

Copy link
Collaborator

commented Aug 5, 2019

Thanks for reporting. ObjectBox uses the simple class name to uniquely identify an entity, it does not differentiate by package name. So as you did make sure each entity class has a unique name.

The error is misleading, the processor does not detect and error correctly if another entity of the same name is found. We should change that.

Also: there is a newer version of ObjectBox available.

@greenrobot-team greenrobot-team added this to the 2.4.0 milestone Aug 5, 2019
@greenrobot-team greenrobot-team self-assigned this Aug 5, 2019
@pontusstjerna

This comment has been minimized.

Copy link
Author

commented Aug 6, 2019

Perfect! Many thanks!

@greenrobot-team

This comment has been minimized.

Copy link
Collaborator

commented Sep 16, 2019

A proper error is now created in the internal version if a duplicate entity name is detected. This will be available with the next update.

@greenrobot

This comment has been minimized.

Copy link
Member

commented Oct 3, 2019

This is also part of the just released version '2.4.0-RC' - would be great if you could give it a try and report back. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.