0

I am not able to compare java.util.Data with Oracle Timestamp

Date stored in address table is like 29-JUL-13 07.15.57.529000000 PM My Address class is like below

@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@Table(name = "address")
public class Address {

@Id
@GeneratedValue(generator = "assigned-by-code")
@GenericGenerator(name = "assigned-by-code", strategy = "assigned")
@Column(name = "id")
private String id;


@Type(type = "timestamp")
@Column(name = "lastaccesstimestamp")
private Date lastAccessTimestamp;

getter and setter

}


@Query("from Address a where a.associationId =:associationId and a.lastAccessTimestamp >=:lastAccessTimestamp")
List<Address> findLatestUpdatedAddresses(
        @Param("lastAccessTimestamp") Date lastAccessTimestamp,
        @Param("associationId") String associationId);

And lastAccessTimestamp in findlatestUpdateAddress method is Calendar.getInstance().getTime()(e.g Mon Jul 29 10:10:09 IST 2013).

It is giving proper result for month, day and year compression but when there is change in minute, second or hour it is not giving proper result.

For Example if lastAccessTimestamp is Mon Jul 29 10:10:09 IST 2013 and DB date is 30-JUL-13 07.15.57.529000000 PM it will return result

but if lasteAccessTimestamp is Mon Jul 30 07:09:09 IST 2013 it is not giving any result I think hour minute and second part is not considered in compression.

In short for month date and year compression is working fine but for minute second and hour it is not working.

Any suggestion will be appreciated even if there is any alternative solution will be accepted.

4

1 回答 1

0

请尝试替换您的:

@Type(type = "timestamp")

@Temporal(TemporalType.TIMESTAMP)

这个注解会告诉 hibernate 在处理对象映射时包含小时/分钟/秒。

于 2013-07-29T19:17:27.680 回答