You need to enable JavaScript to run this app.
最新活动
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

PUT请求时出现“TransientPropertyValueException:objectreferencesanunsavedtransientinstance”错误

出现这个错误的原因是在更新某个实体对象时,关联对象的主键未被设置或者未保存到数据库中。解决方法是在更新实体对象之前,先保存关联的实体对象,或者设置好关联对象的主键。

示例: 假设有一个Order实体类,其中包含一个ShippingAddress实体类的引用,在更新Order时出现了上述错误:

public class Order { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "shipping_address_id")
private ShippingAddress shippingAddress;

// other fields

}

public class ShippingAddress { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;

private String city;

// other fields

}

在更新Order时,如果ShippingAddress的主键未被设置或未保存到数据库中,就会出现“TransientPropertyValueException”错误:

Order order = orderRepository.findById(orderId).orElseThrow(); ShippingAddress shippingAddress = new ShippingAddress(); shippingAddress.setCity("Beijing"); order.setShippingAddress(shippingAddress); orderRepository.save(order); // 出现“TransientPropertyValueException”错误

解决方法是先保存ShippingAddress对象,然后再更新Order对象:

ShippingAddress shippingAddress = new ShippingAddress(); shippingAddress.setCity("Beijing"); shippingAddressRepository.save(shippingAddress); Order order = orderRepository.findById(orderId).orElseThrow(); order.setShippingAddress(shippingAddress); orderRepository.save(order); // 保存成功

本文内容通过AI工具匹配关键字智能整合而成,仅供参考,火山引擎不对内容的真实、准确或完整作任何形式的承诺。如有任何问题或意见,您可以通过联系service@volcengine.com进行反馈,火山引擎收到您的反馈后将及时答复和处理。
展开更多
面向开发者的云福利中心,ECS 60元/年,域名1元起,助力开发者快速在云上构建可靠应用

社区干货

干货 | BitSail Connector 开发详解系列一:Source

throws IOException; /** * Indicate the Source type. */ Boundedness getSourceBoundedness(); /** * Create Source Reader. */ SourceReader createReader(SourceReader.Context reader... getSplitCoordinatorCheckpointSerializer() { return new SimpleBinarySerializer<>(); } /** * Create type info converter for the source, default value {@link BitSailTypeInfoConverter} */...

干货 | BitSail Connector开发详解系列一:Source

throws IOException; /** * Indicate the Source type. */ Boundedness getSourceBoundedness(); /** ... default value {@link BitSailTypeInfoConverter} */ default TypeInfoConverter createTypeInfoConverter() { return new BitSailTypeInfoConverter(); ...

[BitSail] Connector开发详解系列三:SourceReader

(SOURCE_READER_INSTANCE_NAME_TEMPLATE, cluster, topic, consumerGroup, UUID.randomUUID())); consumer.setConsumerPullTimeoutMillis(pollTimeout); consumer.start(); } catch (Exception ... [] typeInfos; private String[] fieldNames; private transient DeserializationSchema deserializationSchema; public TextInputFormatDeserializationSchema(BitSailConfiguration deserializationCon...

干货 | 如何快速实现BitSail Connector?

同时创建自己的工作分支,使用该分支开发自己的Connector。项目地址:[https://github.com/bytedance/bitsail.git。](https://github.com/bytedance/bitsail.git%E3%80%82)项目结构如下:![image.png](https://... [] typeInfos; private final transient int totalCount; private final transient RateLimiter fakeGenerateRate; private final transient AtomicLong counter; private final FakeRowGenerator fakeR...

特惠活动

热门爆款云服务器

100%性能独享,更高内存性能更佳,学习测试、web前端、企业应用首选,每日花费低至0.55元
60.00/1212.00/年
立即购买

域名注册服务

cn/top/com等热门域名,首年低至1元,邮箱建站必选
1.00/首年起32.00/首年起
立即购买

DCDN国内流量包100G

同时抵扣CDN与DCDN两种流量消耗,加速分发更实惠
2.00/20.00/年
立即购买

PUT请求时出现“TransientPropertyValueException:objectreferencesanunsavedtransientinstance”错误 -优选内容

干货 | BitSail Connector 开发详解系列一:Source
throws IOException; /** * Indicate the Source type. */ Boundedness getSourceBoundedness(); /** * Create Source Reader. */ SourceReader createReader(SourceReader.Context reader... getSplitCoordinatorCheckpointSerializer() { return new SimpleBinarySerializer<>(); } /** * Create type info converter for the source, default value {@link BitSailTypeInfoConverter} */...
干货 | BitSail Connector开发详解系列一:Source
throws IOException; /** * Indicate the Source type. */ Boundedness getSourceBoundedness(); /** ... default value {@link BitSailTypeInfoConverter} */ default TypeInfoConverter createTypeInfoConverter() { return new BitSailTypeInfoConverter(); ...
[BitSail] Connector开发详解系列三:SourceReader
(SOURCE_READER_INSTANCE_NAME_TEMPLATE, cluster, topic, consumerGroup, UUID.randomUUID())); consumer.setConsumerPullTimeoutMillis(pollTimeout); consumer.start(); } catch (Exception ... [] typeInfos; private String[] fieldNames; private transient DeserializationSchema deserializationSchema; public TextInputFormatDeserializationSchema(BitSailConfiguration deserializationCon...
干货 | 如何快速实现BitSail Connector?
同时创建自己的工作分支,使用该分支开发自己的Connector。项目地址:[https://github.com/bytedance/bitsail.git。](https://github.com/bytedance/bitsail.git%E3%80%82)项目结构如下:![image.png](https://... [] typeInfos; private final transient int totalCount; private final transient RateLimiter fakeGenerateRate; private final transient AtomicLong counter; private final FakeRowGenerator fakeR...

PUT请求时出现“TransientPropertyValueException:objectreferencesanunsavedtransientinstance”错误 -相关内容

特惠活动

热门爆款云服务器

100%性能独享,更高内存性能更佳,学习测试、web前端、企业应用首选,每日花费低至0.55元
60.00/1212.00/年
立即购买

域名注册服务

cn/top/com等热门域名,首年低至1元,邮箱建站必选
1.00/首年起32.00/首年起
立即购买

DCDN国内流量包100G

同时抵扣CDN与DCDN两种流量消耗,加速分发更实惠
2.00/20.00/年
立即购买

产品体验

体验中心

云服务器特惠

云服务器
云服务器ECS新人特惠
立即抢购

白皮书

一图详解大模型
浓缩大模型架构,厘清生产和应用链路关系
立即获取

最新活动

爆款1核2G共享型服务器

首年60元,每月仅需5元,限量秒杀
立即抢购

火山引擎增长体验专区

丰富能力激励企业快速增长
查看详情

数据智能VeDI

易用的高性能大数据产品家族
了解详情

一键开启云上增长新空间

立即咨询