You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class Account {
@Id
private String id;
private String owner;
@OneToOne
@JoinColumn(name = "statusId")
private Status status;
}
My AccountStatus class:
public class Status {
@Id
private String id = UUID.randomUUID().toString().toUpperCase();
private String name;
public Status(String name){
this.name = name;
}
}
My query with JPA
public Account findAccount(String owner){
Account account = this.streamer.stream(Account.class).filter(
Account$.owner.equal(owner)
).findFirst().orElseThrow(AccountNotFound::new);
if (account.getStatus().getName().equalsIgnoreCase("CLOSED"))
throw new AccountNotFound();
return account;
}
Sometimes the AccountStatus wasn't load and returning error. I fixed this bug changing JPAStream query to JPQL
The text was updated successfully, but these errors were encountered:
Could you provide more information? For example, under which conditions the Status is not loaded. If it is not loaded, is null returned instead? Can you provide the logs of SQL. Did you also try joining the tables (e.g. using StreamConfiguration?
SQL: select account0_.id as account_3_0_, account0_.status_id as account_9_0_, account0_.owner as owner6_0_ from account account0_ where account0_.owner=?
It was hard to debug because it's rare for the account's status object to return null, but sometimes it did return. I did not try joining the tables
And the account status returned null for the same account, and when I went to check the database, the status was filled.
Hi, I would love to take a closer look at this issue. However, it isn't easy to reproduce without your database and code example. Are you able to provide any more information?
Generally, I recommend performing a join when in need of information from another table. In this case that would look like this:
I tried to reproduce the error here and was unsuccessful, but what I noticed was that even marking the property with fetch type lazy, the property was still loaded.
Thanks for the update, as both of us failed to reproduce the issue I will close it for now.
Regarding the fetching, that is a question for the underlying JPA provider. JPAStreamer does not interact with the database directly (only via the JPA provider) and thus cannot control how the data is fetched.
My Account class:
My AccountStatus class:
My query with JPA
Sometimes the AccountStatus wasn't load and returning error. I fixed this bug changing JPAStream query to JPQL
The text was updated successfully, but these errors were encountered: