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

Add support for passing the mapping Class to Json Types #133

Closed
vladmihalcea opened this issue Sep 17, 2019 · 1 comment
Closed

Add support for passing the mapping Class to Json Types #133

vladmihalcea opened this issue Sep 17, 2019 · 1 comment
Milestone

Comments

@vladmihalcea
Copy link
Owner

vladmihalcea commented Sep 17, 2019

Currently, the mapping Type is resolved by scanning the annotated entity attribute. However, if we want to execute a query like this one:

JsonNode ratings = (JsonNode) entityManager
.createNativeQuery(
	"SELECT " +
	"  JSON_QUERY(properties, '$.reviews') AS ratings " +
	"FROM book " +
	"WHERE " +
	"  JSON_VALUE(properties, '$.title') = :title", Tuple.class)
.setParameter("title", "High-Performance Java Persistence")
.unwrap(NativeQuery.class)
.addScalar("ratings", JsonStringType.INSTANCE)        
.getSingleResult();

We will get a NullPointerException as the Java descriptor will not be able to resolve the expected mapping Class:

java.lang.NullPointerException
	at java.lang.Class.isAssignableFrom(Native Method)
	at com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor.fromString(JsonTypeDescriptor.java:104)
	at com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor.wrap(JsonTypeDescriptor.java:165)
	at com.vladmihalcea.hibernate.type.json.internal.AbstractJsonSqlTypeDescriptor$1.doExtract(AbstractJsonSqlTypeDescriptor.java:34)
@vladmihalcea
Copy link
Owner Author

Fixed.

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

1 participant