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

Filter based on SubEntity (ManyToOne relation) #393

Open
creoludifico opened this issue Mar 15, 2024 · 2 comments
Open

Filter based on SubEntity (ManyToOne relation) #393

creoludifico opened this issue Mar 15, 2024 · 2 comments
Assignees

Comments

@creoludifico
Copy link

Hi

I've not found any example on how to filter a entity based on some value inside a sub entity.

Assume this is my MainEntity

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "MAIN_ENTITY", schema = "Q")
public class MainEntity {

	...

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SubEntityID", insertable = false, updatable = false)
    private SubEntity subEntity;
	
	...
}

And this is some service where i'm trying to filter on the subentity

var username = "bob"
	
/*
   Gets the main entities (I would like the filter for the ManyToOne entity here)
*/
var entities = jpaStreamer.stream(of(MainEntity.class).joining(MainEntity$.subEntity))
		.filter(MainEntity$.username.equal(username))
		//.filter(MainEntity$.subEntity.state.notEqual("DONE")) <-Doesnt work..
		.toList();
		
/*
   Have to do it like this. Filter the main entities from the subEntity.. 
   This results in slower performance because it's no longer part of the SQL query
*/
var filteredEntities = new ArrayList<MainEntity>();
entities.forEach(entity -> {
	if(!(entity.getSubEntity().getState().equals("DONE"))){
		filteredEntities.add(entity);
	}
});

Is this possible in JpaStreamer? I know it's possible in Entity Framework and LINQ from C# ;)

@mbuchner
Copy link

@creoludifico Did you find any solution for this?

If filters on joined entities are not possible the whole framework doesn't really make sense for enterprise applications.

+1

@sasanyi
Copy link

sasanyi commented Jul 9, 2024

The same problem here. Does anyone have a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants