大家好我有奇怪的问题。我有完全hibernate + spring的应用程序。如果我只使用hibernate来添加/编辑/删除对象,那么一切都很有效。但是,当我直接在DB应用程序上进行更改时,看不到更改? (不要更新它们)。我的坚持很简单:
<persistence-unit name="allegroTransactionPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/AllegroShop?UseUnicode=true&characterEncoding=utf8" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="topSecret" />
<property name="hibernate.connection.password" value="topSecret" />
<!-- <property name="hibernate.hbm2ddl.auto" value="create" /> -->
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="show_sql" value="true" />
<property name="hibernate.hbm2ddl.import_files" value="/SQL/payment_type.sql"/>
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
<property name="hibernate.connection.charSet" value="UTF-8" />
</properties>
</persistence-unit>
</persistence>
我的示例课程也不难理解:
@Entity(name = "PAYMENT_TYPE")
public class PaymentTypeImpl implements PaymentType {
@Id
@Column(name = "PAYMENT_ID")
@GeneratedValue(strategy = GenerationType.AUTO)
protected Long id;
@Column(name = "PAYMENT_NAME")
protected String paymentName;
@Column(name = "PRICE", nullable = false)
protected float paymentPrice;
@Column(name = "ACTIVE")
protected boolean active;
@Override
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
@Override
public String getPaymentName() {
return paymentName;
}
@Override
public void setPaymentName(String paymentName) {
this.paymentName = paymentName;
}
@Override
public boolean getActive(){
return active;
}
@Override
public boolean isActive(){
return active;
}
@Override
public void setActive(boolean active) {
this.active = active;
}
@Override
public float getPaymentPrice() {
return paymentPrice;
}
@Override
public void setPaymentPrice(float paymentPrice) {
this.paymentPrice = paymentPrice;
}
}
有什么想法吗?任何可以帮助我的链接?
答案 0 :(得分:0)
如果您在直接更新之前已经读过实体,这可能是由休眠二级缓存引起的。您可以在实体上使用@Cacheable(false)
注释将其禁用,这当然可能会影响性能。