@Entity
public class ESoftDelBook extends BaseSoftDelete {
String bookTitle;
@ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
ESoftDelUser lendBy;
...
}
ESoftDelUser user1 = new ESoftDelUser("user1");
Ebean.save(user1);
ESoftDelBook book1 = new ESoftDelBook("book1");
book1.setLendBy(user1);
Ebean.save(book1);
// now I delete user1
Ebean.delete(user1);
// and fetch the book again from the DB:
book1 = Ebean.find(ESoftDelBook.class).where().eq("bookTitle", "book1").findUnique();
--
---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
That is, the last assert then becomes:ESoftDelUser lendBy = book1.getLendBy();
assertThat(lendBy.isDeleted()).isTrue();How does that sound?
public getUser() {
if (user == null || user.isDeleted()) return null; // I see a problem, if query.temporalMode=SOFT_DELETE
return user;
}
Cheers, Rob.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
> It's not exactly what I wantUser is a "reference bean" at this point. That is, it only have it's Id value set.To try and make it null we would need Ebean to actually hit the DB to check the deleted status ... and the implication is that we would get Ebean to do that anytime it created a reference bean on a entity type with soft delete support - this could get expensive.
Hence, the approach of leaving the bean as non-null ... and setting isDeleted() to true for this use case.
An alternative it that prior to deleting user1 set the associated lendBy references in books to null - Update books set lendBy = null where lendBy = user1
Is there another approach? Or do you really want Ebean to hit the DB and check the deleted status for reference beans?
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
> I think if getLendBy is called, we can afford the DB-hit to check if it is deleted and return null in this caseTo be clear ... getLendBy does not invoke a query but just returns the reference bean. There is no "is this deleted" check at that point.
It is not until a property on the bean is read that lazy loading is invoked on the reference bean ... and that sql query returns 0 rows due to being logically deleted and at that point Ebean can interpret that as "the bean you tried to lazy load has been logically deleted" and sets the soft deleted property to true.That is, the timing of when the logical delete is checked is relatively late (and if it is earlier then we have to hit the DB for each reference bean).
Book book = server.find
User user = book.getLendBy(); // you: return an unchecked reference bean / I: perform a DB hit to check isDeleted and return null
if (user != null) {
System.out.println("The book is lent by " + user.getName()); // you: hit the DB here and return null / I: this line would not be executed
}
System.out.println("The book is lent by " + user.getName());
}--
---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.