Status Update
Comments
da...@google.com <da...@google.com> #2
This is probably happening because there are multiple instances of DataStore active. You should consider managing the DataStore as a singleton. See the attached bug for more info.
an...@gmail.com <an...@gmail.com> #3
I stripped the project down to the attached sample.
It doesn't use the relation, and I left Transaction2 there, although it's unused. The problem can be seen in the PaymentDao_Impl generated class.
Thanks.
It doesn't use the relation, and I left Transaction2 there, although it's unused. The problem can be seen in the PaymentDao_Impl generated class.
Thanks.
Description
Version used: 1.1.1
Devices/Android versions reproduced on: Any (generated code)
public class Transaction {
...
@Embedded
private Money amount;
public class Payment extends Transaction {
...
public Payment(@NonNull Long transactionId, @NonNull Date date, Money amount, String company, String notes,
@NonNull Long invoiceId, @NonNull PaymentMethod paymentMethod, Double cryptoAmount) {
super(transactionId, date, amount, company, notes);
public class Shipment extends Transaction {
...
public Shipment(@NonNull Long transactionId, @NonNull Date date, Money amount, String company, String notes,
@NonNull Long orderId, @NonNull ShipmentMethod shipmentMethod,
@NonNull String name, @NonNull String address, @NonNull String country,
String trackingNumber, String weight, String dimensions) {
super(transactionId, date, amount, company, notes);
Generated code from Dao classes:
Fetching relation, OK:
_item_1 = new Payment(_tmpTransactionId,_tmpDate,_tmpAmount,_tmpCompany,_tmpNotes,_tmpInvoiceId,_tmpPaymentMethod,_tmpCryptoAmount);
Fetching relation, not OK - 3rd argument is null even though _tmpAmount has been set:
final Money _tmpAmount;
if (! (_cursor.isNull(_cursorIndexOfCurrency) && _cursor.isNull(_cursorIndexOfExchangeRate) && _cursor.isNull(_cursorIndexOfAmount))) {
...
_tmpAmount = new Money(_tmpCurrency,_tmpExchangeRate,_tmpAmount_1);
} else {
_tmpAmount = null;
}
_item_1 = new Shipment(_tmpTransactionId,_tmpDate,null,_tmpCompany,_tmpNotes,_tmpOrderId,_tmpShipmentMethod,_tmpName,_tmpAddress,_tmpCountry,_tmpTrackingNumber,_tmpWeight,_tmpDimensions);
Another case, from a @Query generated method:
_result = new Shipment(_tmpTransactionId,_tmpDate,null,_tmpCompany,_tmpNotes,_tmpOrderId,_tmpShipmentMethod,_tmpName,_tmpAddress,_tmpCountry,_tmpTrackingNumber,_tmpWeight,_tmpDimensions);
Using trial and error, I found that creating another class Transaction2 that is an exact copy of Transaction, and having Shipment extend from it:
public class Shipment extends Transaction2 {
works around the problem:
_item_1 = new Shipment(_tmpTransactionId,_tmpDate,_tmpAmount,_tmpCompany,_tmpNotes,_tmpOrderId,_tmpShipmentMethod,_tmpName,_tmpAddress,_tmpCountry,_tmpTrackingNumber,_tmpWeight,_tmpDimensions);
_result = new Shipment(_tmpTransactionId,_tmpDate,_tmpAmount,_tmpCompany,_tmpNotes,_tmpOrderId,_tmpShipmentMethod,_tmpName,_tmpAddress,_tmpCountry,_tmpTrackingNumber,_tmpWeight,_tmpDimensions);
My hypothesis is that since Shipment is lexically after Payment, the Room compiler handles Payment correctly, but not Shipment.