gpt4 book ai didi

java - 我无法使用 hibernate 本地 session 工厂对象更新特定行的 'shop_table' 表值?

转载 作者:搜寻专家 更新时间:2023-10-30 20:33:28 25 4
gpt4 key购买 nike

如果我正在打印 session 对象,所需的输出不正确,即 -

SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=org.hibernate.engine.spi.ExecutableList@7164ee40 updates=org.hibernate.engine.spi.ExecutableList@2d80b7f deletions=org.hibernate.engine.spi.ExecutableList@560d3d76 orphanRemovals=org.hibernate.engine.spi.ExecutableList@10fbc8b2 collectionCreations=org.hibernate.engine.spi.ExecutableList@463b2203 collectionRemovals=org.hibernate.engine.spi.ExecutableList@47a5a48 collectionUpdates=org.hibernate.engine.spi.ExecutableList@3b23213c collectionQueuedOps=org.hibernate.engine.spi.ExecutableList@75d3c0b2 unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])

我认为如果像这样打印很有值(value)-

SessionImpl(PersistenceContext[entityKeys=[EntityKey[com.mode
l.Entity#1]],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[
] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]])

我的商店类(class)是-

@Entity
@Table(name = "shops")
public class Shop {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name = "shop_domain")
private String shopDomain;
@JsonFormat(pattern="dd-MM-yyyy")
private Timestamp orderSyncDate;
@OneToOne(mappedBy = "shop", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JsonManagedReference
private NetsuiteConfig netsuiteConfig;

我只是将一些数据设置为商店类对象,试图保存在数据库中,对象持有 ID 即已经存在于数据库中,查询为 -session factory.getCurrentSession().update(shop);这实际上并没有更新数据库中的值,我不知道原因,为什么?

最佳答案

您必须提交更新才能将更改传播到数据库中:

...
sessionFactory.getCurrentSession().update(shop);
sessionFactory.getCurrentSession().commit();
...

引用资料:

关于java - 我无法使用 hibernate 本地 session 工厂对象更新特定行的 'shop_table' 表值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55726423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com