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

Range.infiniteClosed is saving the max value as if it was Open #548

Open
whithang opened this issue Jan 3, 2023 · 6 comments
Open

Range.infiniteClosed is saving the max value as if it was Open #548

whithang opened this issue Jan 3, 2023 · 6 comments

Comments

@whithang
Copy link

whithang commented Jan 3, 2023

i'm using the closed method like Range.infiniteClosed(3010) but the value is being saved in the postgres database as (,3011)
it should be saving as (,3010]

i am importing the latest version of the library: implementation 'com.vladmihalcea:hibernate-types-52:2.21.1'

the database column is defined in the Hibernate Entity as @Column(columnDefinition = "int4range") private Range<Integer> priceRange

the postgres database column is defined as type int4range

@vladmihalcea
Copy link
Owner

vladmihalcea commented Jan 3, 2023

i am importing the latest version of the library: implementation 'com.vladmihalcea:hibernate-types-52:2.21.1'

That's no longer the latest version of the product, which is now called Hypersistence Utils, and the version is 3.0.1.

Try to provide a replicating test case in the existing PostgreSQLRangeTypeTest so that we have a starting point for the investigation.

If you can find the issue, then please provide a Pull Request with the fix.

@whithang
Copy link
Author

whithang commented Jan 3, 2023

ok - i updated my import and am still seeing the issue.
so i created a test that repro's the issue.
but i don't seem to be able to push a branch to your repo. i'm getting back a 403

remote: Permission to vladmihalcea/hypersistence-utils.git denied to whithang.
fatal: unable to access 'https://github.com/vladmihalcea/hypersistence-utils.git/': The requested URL returned error: 403

@whithang
Copy link
Author

whithang commented Jan 3, 2023

here's the test:

@Test
    public void testClosedRange() {
        int upperLimit = 10;

        Restriction _restriction = doInJPA(entityManager -> {
            Restriction restriction = new Restriction();
            restriction.setRangeInt(Range.infiniteClosed(upperLimit));
            entityManager.persist(restriction);

            return restriction;
        });

        doInJPA(entityManager -> {
            Restriction restriction = entityManager.find(Restriction.class, _restriction.getId());

            assertEquals(upperLimit, Optional.ofNullable(restriction.getRangeInt().upper()));
        });
    }

@vladmihalcea
Copy link
Owner

You have to fork the repository and push to your own fork.

Then, you can send the Pull Request from your fork and I could review it.

@vladmihalcea
Copy link
Owner

Test cases can be found in #550

@nstdio
Copy link
Contributor

nstdio commented Aug 26, 2023

I've looked into it and Range.infiniteClosed(3010) produces as expected (,3010] and inserted as is. However, when selecting Postgres itself returns mathematically valid (,3011). I'm not sure what can be done here.

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

No branches or pull requests

3 participants