0
I以下のエンティティがあります。Hibernateは、削除されません@PrePersistと@PreUpdate
@Entity
@Table(name="accounts")
public class AccountEntity extends TimestampAbstractEntity {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name = "id")
private int id;
}
TimestampAbstractEntity:セッションから削除する方法がまったく機能していない
@MappedSuperclass
public abstract class TimestampAbstractEntity implements Serializable{
@Column(name = "created_at", columnDefinition = "DATETIME")
@Temporal(TemporalType.TIMESTAMP)
private Date createdAt;
@Column(name = "updated_at", columnDefinition = "DATETIME")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedAt;
public Date getCreatedAt() {
return createdAt;
}
@PrePersist
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
@PreUpdate
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
}
、いなくてもログをが示されている。 私は、私が休止状態-コア5.1.0.Final
を使用しています
getCurrentSession().createQuery(delete from yadada where id=:id).setInteger("id", id).executeUpdate();
ログポップポップアップしますが、何もデータベースに起こりませんを使用して回避策を試してみましたが、私の構成は次のとおりです。
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
configuration.setProperty("hibernate.current_session_context_class", "thread");
configuration.setProperty("hibernate.id.new_generator_mappings", "false");
configuration.setProperty("hibernate.show_sql", "true");
configuration.addAnnotatedClass(AccountEntity.class);
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties());
return configuration.buildSessionFactory(builder.build());
を、あなたがトランザクション内で削除を実行していますか? – Pace
createSqlQueryを使用してください。具体的にはhqlを使用する必要がありますか? – PeaceIsPearl
@Paceいずれかの方法で動作しません – Lundira