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

Issue with filering fields of type Time and Timestamp #22

Open
raaj31sharma opened this issue Nov 8, 2021 · 13 comments
Open

Issue with filering fields of type Time and Timestamp #22

raaj31sharma opened this issue Nov 8, 2021 · 13 comments

Comments

@raaj31sharma
Copy link

I have Entity class A which has this timestamp type field say "startTime". I want to filter records on the basis of "startTime".

I tried this way :
filter=startTime:GTE:ts'2021-12-10T10:00:00:000Z' - Here startTime corresponds to Timestamp field in MY SQL
filter=startTime:GTE:ts'10:00:00' - Here startTime corresponds to Time field in MY SQL
Although I am not getting any error as such but looks like this filter is getting ignored while fetching the data.

Kindly help me to understand how to pass the time and timestamp fields in the request query

@cen1
Copy link
Contributor

cen1 commented Nov 8, 2021

Have you tried without the ts prefix?

@raaj31sharma
Copy link
Author

raaj31sharma commented Nov 9, 2021

With or without ts, I am not able to get the response in the second case (Time)
filter=startTime:GTE:ts'10:00:00'

It is not able to pick the query, giving the error as either "ts" or "10:00:00" is not a text type.

Is there any other way to pass the Time type filter?

@cen1
Copy link
Contributor

cen1 commented Nov 9, 2021

I took a quick look at the code and I think there is currently no support for Time fields, only dates, datetimes and timestamps. Can you share your JPA entity class (or at least a subset with the time field)?

@raaj31sharma
Copy link
Author

raaj31sharma commented Nov 10, 2021

@TeMPOraL( TemporalType.TIME )
@column( name = "start_time" )
private Date startTime;

This is the way I am using the field in my entity class. I also feel that type Time is not handled in the code.

NOTE : There is one more issue I am facing that is regarding getting the count of the records using the utils method.
When I am using the nested structure, say, passing (filter=entries.userId:EQ:user1) where one record can have multiple entries.

In this case the util method is giving me the count of entries rather than the count of records. While record.class is being passed as the method parameter. I was expecting the method to return the count of records.

Although if the search filter is applied on the main class fields it works fine.

@cen1
Copy link
Contributor

cen1 commented Nov 10, 2021

Code checks the class in the model directly, ignoring any JPA annotations such as @Temporal so the end solution would probably look at LocalTime instead. If you are using JPA 2.2 and Java 8+ that should not be an issue. But it looks like it doesn't check for LocalTime either right now. I will try to prepare a repro and a fix in the following days.

If you need an immediate workaround you can have a separate query parameter and pass it as a custom filter into JPAUtils.

Although if the search filter is applied on the main class fields it works fine.

Not sure I quite grasped what you were saying here. Can you give me an example of the JPAUtils call in each case?

@raaj31sharma
Copy link
Author

queryEntitiesCount(EntityManager em, Class entity, QueryParameters q)
This is the method I am using to get the count of the records. There are 2 scenarios:
1: When I am searching using fields of Class passed in the parameter. eg: filter=color:EQ:red
This is working fine and giving the correct count.

2: When I am searching using fields of a nested class. Eg: filter=entries.userId:EQ:user1 where a list of entry is the field of Class.
This is not giving me the count of the Class instead giving me the count of entries which should not happen.

In laymen's term if I say, A record have multiple entries, and if the search criteria is applied on the field of entry class, In the result it is returning the count of entries instead of the records. Although it should always be the count of records.

@osbeorn osbeorn mentioned this issue Nov 21, 2021
@osbeorn
Copy link
Member

osbeorn commented Nov 21, 2021

I have added filtering support for LocalTime and OffsetTime fields. Use these types instead of Date with @TeMPOraL annotation.

I have also fixed the queryEntitiesCount method, which was applying DISTINCT in a wrong way.

@raaj31sharma
Copy link
Author

Can you please merge the code and release the latest version so that I will be able to use and test the scenario.

Thanks

@MBJuric
Copy link
Member

MBJuric commented Nov 22, 2021

Hi, we will include this in the next regular release in a few weeks.
In the meantime you can use the snapshot repository to use the latest unreleased version.
Best regards

@raaj31sharma
Copy link
Author

raaj31sharma commented Nov 22, 2021

I used the below mentioned snapshot version:

com.kumuluz.ee.rest
kumuluzee-rest
1.6.0-SNAPSHOT

But it is giving me the below error:

"The POM for com.kumuluz.ee.rest:kumuluzee-rest:jar:1.6.0-SNAPSHOT is missing, no dependency information available"

Is it the right way to use? If not, please let me know how to use it.

Thanks

@osbeorn
Copy link
Member

osbeorn commented Nov 23, 2021

@raaj31sharma please check again. Version 1.6.0-SNAPSHOT should now be available.

@raaj31sharma
Copy link
Author

@osbeorn It is still not working, getting error as not able to download jar from proximity. Pls let me know if its to be used in a different way. As of now I am using in the same way as mentioned above.

@raaj31sharma
Copy link
Author

raaj31sharma commented Nov 25, 2021

I am using the following dependency to use the snapshot version:

com.kumuluz.ee.rest
kumuluzee-rest
1.6.0-SNAPSHOT

Getting the following error:
Could not find artifact com.kumuluz.ee.rest:kumuluzee-rest:pom:1.6.0-SNAPSHOT in proximity (https://repository.abc.com/content/groups/public/)

Please let me know if there is a different way to use this.

Also, exactly when are you planning to release the next version of the library.

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