請幫幫我。使用休眠異常
粉碎插入表格數據,列setCreateDate
。誰知道這個錯誤是什麼,爲什麼沒有可能寫一個時間戳DateTime
對象?
Caused by: org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: "2015-02-24 13:48:32.575000 +02:00:00"
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:500)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:334)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:93)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:56)
... 56 more
類道:
import com.tatem.persistance.dao.core.GenericDao;
import com.tatem.persistance.domain.core.DomainObject;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import java.io.Serializable;
import java.util.List;
public class GenericDaoHibernate<T extends DomainObject> implements GenericDao<T> {
private Class<T> type;
@Autowired
private HibernateTemplate hibernateTemplate;
@Autowired
private SessionFactory sessionFactory;
public GenericDaoHibernate(Class<T> type) {
this.type = type;
}
@Override
public T get(Serializable id) {
return hibernateTemplate.get(type, id);
}
@Override
public List<T> getAll() {
return hibernateTemplate.loadAll(type);
}
@Override
public Serializable save(T object) {
Serializable id = (Serializable) hibernateTemplate.save(object);
hibernateTemplate.flush();
return id;
}
@Override
public void saveBulk(List<T> objects){
hibernateTemplate.saveOrUpdateAll(objects);
hibernateTemplate.flush();
}
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
@Override
public void merge(T object) {
hibernateTemplate.merge(object);
hibernateTemplate.flush();
}
@Override
public void update(T object){
hibernateTemplate.update(object);
hibernateTemplate.flush();
}
@Override
public void delete(T object) {
hibernateTemplate.delete(object);
hibernateTemplate.flush();
}
@Override
public void deleteAll(List<T> objects) {
hibernateTemplate.deleteAll(objects);
hibernateTemplate.flush();
}
@Override
public void bulkSaveOrUpdate(List<T> objects) {
hibernateTemplate.saveOrUpdateAll(objects);
hibernateTemplate.flush();
}
}
類休眠:
import com.tatem.bookingserver.rest.json.model.notification.InternalNotificationType;
import com.tatem.persistance.domain.core.DomainObject;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import javax.persistence.*;
@Entity
@Table(name = "internal_notification")
public class InternalNotificationEntity implements DomainObject {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "user_id")
private long userId;
@Column(name = "created_ts")
@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
private DateTime createDate;
@Enumerated(EnumType.STRING)
private InternalNotificationType type;
@Column
private String message;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public DateTime getCreateDate() {
return createDate;
}
public void setCreateDate(DateTime createDate) {
this.createDate = createDate;
}
public InternalNotificationType getType() {
return type;
}
public void setType(InternalNotificationType type) {
this.type = type;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
}
貌似你試圖保存日期轉換成int的列。 – StanislavL 2015-02-24 12:55:20
檢查您的數據庫表,看起來您嘗試保存在時間戳中的列不是正確的類型。 – 2015-02-24 13:03:58
不知道postgress,但時區與時區和時間戳之間沒有區別嗎? – mpkorstanje 2015-02-24 14:23:44