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

Any plans to support Hibernate 6? #21

Open
pavilalopes opened this issue May 13, 2024 · 4 comments
Open

Any plans to support Hibernate 6? #21

pavilalopes opened this issue May 13, 2024 · 4 comments

Comments

@pavilalopes
Copy link

No description provided.

@pavilalopes
Copy link
Author

Adapting to Hibernate 6 should not be too hard. For anyone looking to DYI, here's what BoxType should look like (caution: not tested):

public class BoxType implements UserType<Box> {

    @Override
    public int getSqlType() {
        return java.sql.Types.OTHER;
    }

    @Override
    public Class<Box> returnedClass() {
        return Box.class;
    }

    @Override
    public boolean equals(Box b1, Box b2) throws HibernateException {
        if (b1 == null && b2 == null)
            return true;
        else if (b1 == null || b2 == null)
            return false;
        return b1.equals(b2);
    }

    @Override
    public Box nullSafeGet(ResultSet resultSet, int position, SharedSessionContractImplementor sessionImplementor, Object owner)
            throws HibernateException, SQLException {

        PGbox value = (PGbox) resultSet.getObject(position);

        if (value == null) {
            return null;
        } else {
            Point p1 = new Point(value.point[0].x, value.point[0].y);
            Point p2 = new Point(value.point[1].x, value.point[1].y);
            return new Box(p1, p2);
        }
    }

    @Override
    public void nullSafeSet(PreparedStatement preparedStatement, Box box, int i, SharedSessionContractImplementor sessionImplementor) throws HibernateException, SQLException {
        if (box == null) {
            preparedStatement.setNull(i, java.sql.Types.OTHER);
        } else {
            preparedStatement.setObject(i, new PGbox(box.getP1().getX(), box.getP1().getY(),
                    box.getP2().getX(), box.getP2().getY()));
        }
    }

    @Override
    public Box deepCopy(Box b) throws HibernateException {
        if (b == null)
            return null;

        try {
            return (Box) b.clone();
        } catch (CloneNotSupportedException e) {
            throw new IllegalArgumentException(e.toString());
        }
    }

    @Override
    public boolean isMutable() {
        return false;
    }

    @Override
    public int hashCode(Box b) throws HibernateException {
        return b.hashCode();
    }

    @Override
    public Serializable disassemble(Box b) throws HibernateException {
        return b;
    }

    @Override
    public Box assemble(Serializable cached, Object owner) throws HibernateException {
        return (Box) cached;
    }

    @Override
    public Box replace(Box original, Box target, Object owner) throws HibernateException {
        return original;
    }
}

@The-Alchemist
Copy link
Owner

Apologies for the delay, @pavilalopes .

jsonb is superior in almost every way, and I'd recommend using that. Do you have a specific need for hstore and Hibernate 6? Maybe an old version of PostgreSQL?

@pavilalopes
Copy link
Author

pavilalopes commented May 27, 2024

We're not actually using this library for that kind of type, we're using it for the geometric types (point, etc). From what I can tell there is still no other library that covers these types.
Hibernate 6 can handle more Postgres types out of the box (native arrays for example) and https://github.com/vladmihalcea/hypersistence-utils covers more types above that, but not all of them.

@The-Alchemist
Copy link
Owner

@pavilalopes : Totally makes sense. I would recommend you send a PR to hypersistence-utils, though, as this project is basically archived. (I should mark it as such.)

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