javapostgresqlhibernatehibernate-restrictions

Comparing two columns in Hibernate Criteria


I have a table in Postgre Database. The table has 2 timestamp format columns. I need those rows where one column timestamp is not equals the second column timestamp.

For the below query I need the Hibernate criteria restrictions.

select * from A where column1<>column2


Solution

  • Given your comment here, you'll have to do a full table scan, which will create troubles with a bigger table. You will likely need to change your approach altogether, and introduce a field which says something like "IsUpdated". Or, when creating that record, UpdatedTime should be set to null, indicating it hasn't been updated yet. Then, you can do a query like "give all records where UpdatedTime is not null".