- Notifications
You must be signed in to change notification settings - Fork136
Open
Description
Jimmer Version
0.9.113
JDK Version
JDK21
Database
Postgres
OS
Linux
Expected behavior
Get an object with applied filtering by backward association
Actual behavior
Get an object without filtering by backward association
Description
The select for inner objects is generated without a predicate in where
Reproduction steps
var document = DocumentDraft.$.produce(documentDraft -> { documentDraft.setType("type"); documentDraft.addIntoFiles(fileDraft -> { fileDraft.setLink("link1"); }); documentDraft.addIntoFiles(fileDraft -> { fileDraft.setLink("link2"); }); }); var newDocument = sqlClient.saveCommand(document) .setMode(SaveMode.INSERT_ONLY) .setAssociatedModeAll(AssociatedSaveMode.APPEND) .execute() .getModifiedEntity(); // Need to get a document with a specific fileId var documentTable = DocumentTable.$; var documentWithSpecificFile = sqlClient .createQuery(documentTable) .where(documentTable .files(fileTableEx -> fileTableEx.id().eq(newDocument.files().getFirst().id()))) .select( documentTable.fetch( DocumentFetcher.$.allScalarFields().files(FileFetcher.$.allScalarFields()) ) ) .fetchOneOrNull(); System.out.println(documentWithSpecificFile.files().size()); // selected all files, but expected filtered filesGenerated SQL
select tb_1_.ID, tb_1_.TYPEfrom DOCUMENT tb_1_where exists( select 1 from FILE tb_2_ where tb_2_.DOCUMENT_ID = tb_1_.ID and tb_2_.ID = 'd52cf581-46b3-49a1-82a0-c44669918485' )limit 2select tb_1_.ID, tb_1_.LINKfrom FILE tb_1_where tb_1_.DOCUMENT_ID = '3ba9606a-629c-4569-af07-3ca70525975a'Relation Model
@Entitypublic interface Document { @Id @GeneratedValue(generatorType = UUIDIdGenerator.class) @NotNull UUID id(); @Nullable String type(); @OneToMany(mappedBy = "document") @NotNull List<File> files();}@Entitypublic interface File { @Id @GeneratedValue(generatorType = UUIDIdGenerator.class) @NotNull UUID id(); @ManyToOne @NotNull Document document(); @NotNull String link();}create table document( id uuid not null primary key, type varchar(100));create table file( id uuid not null primary key, document_id uuid not null, link text not null);alter table file add foreign key (document_id) references document (id);Screenshots
No response
Logs
No response