Reputation: 41
I have a problem with saving data. Need to have Date field in my entity, but get error
org.postgresql.util.PSQLException: ERROR: column "TIME" cannot be cast to type timestamp without time zone
my entity:
public interface ActivityDays extends Entity{
String getKey();
void setKey(String key);
String getUsername();
void setUsername(String userName);
Date getDate();
void setDate(Date Date);
}
creating date with
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getDefault());
Date date = calendar.getTime();
I know that Date (as same as Timestamp) doesn't have Timezone. Tried a lot of things to do. Is there a possibility to save Date in entities (not in long format)?
Upvotes: 1
Views: 288
Reputation: 41
Found old tables in postgresql, deleted them and generated new. + Used Timestamp instead of Date. Now it works.
Upvotes: 1
Reputation: 13682
I'm not 100% sure, but I think you need to be using java.sql.Timestamp
. It has a constructor that takes milliseconds as a long:
new java.sql.Timestamp(calendar.getTime().getTime());
And then on your interface, use Timestamp instead of Date.
Upvotes: 1