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

Supports create criteria parameter for generic type #610

Open
quaff opened this issue Apr 2, 2024 · 5 comments
Open

Supports create criteria parameter for generic type #610

quaff opened this issue Apr 2, 2024 · 5 comments

Comments

@quaff
Copy link

quaff commented Apr 2, 2024

ParameterExpression<List> parameter = criteriaBuilder.parameter(List.class, "list");

is not type safe, We need add a Super Type Token like TypeReference

ParameterExpression<List<Integer>> parameter = criteriaBuilder.parameter(new TypeReference<List<Integer>>{}, "list");
@gavinking
Copy link
Contributor

You mean like a CDI TypeLiteral, right?

But what is the usecase here? For use with in conditions? Or something else?

@quaff
Copy link
Author

quaff commented Apr 2, 2024

You mean like a CDI TypeLiteral, right?

Yes.

But what is the usecase here? For use with in conditions? Or something else?

Not in but equal.

	@Entity
	public class TestEntity {

		@Id
		@GeneratedValue
		Long id;

		List<Integer> list;

	}
ParameterExpression<List<Integer>> parameter = criteriaBuilder.parameter(List.class);  // cannot compile
Root<TestEntity> root = criteria.from(TestEntity.class);
criteria.select(root).where(criteriaBuilder.equal(root.get(TestEntity_.list), parameter));

@gavinking
Copy link
Contributor

I see. So I suppose this:

List<Integer> list;

is possible in standard JPA with an AttributeConverter.

@quaff
Copy link
Author

quaff commented Apr 2, 2024

I see. So I suppose this:

List<Integer> list;

is possible in standard JPA with an AttributeConverter.

Hibernate will map it to array now, no need AttributeConverter.

@gavinking
Copy link
Contributor

Right, I know that, but that's not standard in the Persistence spec.

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

2 participants