Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate不保存复合键的自定义序列(当其中一个键值已知时)_Java_Hibernate_Transient - Fatal编程技术网

Java Hibernate不保存复合键的自定义序列(当其中一个键值已知时)

Java Hibernate不保存复合键的自定义序列(当其中一个键值已知时),java,hibernate,transient,Java,Hibernate,Transient,我的持久性类ProductVersionElement中有一个id和versionid的复合键。对于每个键,我都有一个自定义的hibernate sequencer作为IdGenerator和VersionIdGenerator @Id @GenericGenerator(name = "custom_id", strategy = "com.model.persistent.sequencer.IdGenerator") @GeneratedValue(generator =

我的持久性类ProductVersionElement中有一个id和versionid的复合键。对于每个键,我都有一个自定义的hibernate sequencer作为IdGenerator和VersionIdGenerator

@Id
    @GenericGenerator(name = "custom_id", strategy = "com.model.persistent.sequencer.IdGenerator")
    @GeneratedValue(generator = "custom_id")
    protected String id;

    @Id
    @GenericGenerator(name = "custom_versionId", strategy = "com.model.persistent.sequencer.VersionIDGenerator")
    @GeneratedValue(generator = "custom_versionId")
    protected String versionId;
案例1。当id和versionid都为null时。然后sequencer为这两个字段填充序列并成功保存ProductVersionElement。保存后,在“调试”中显示两个字段的生成值

案例2:当设置了id(我事先知道该值,只想生成versionid)并且versionid为null时。为此,我更改了sequencer:如果field的值为null,则生成序列,否则返回相同的值

if (id == null) {
   //Generate the sequence and return
} else{
  // return same id
}
在这种情况下,它不会保存ProductVersionElement。即使在保存之后,它也只显示id的值(已经设置),并且versionid在保存之后仍然为null

虽然它不会导致任何异常,但在我尝试保存另一个对象时:包含ProductVersionElement的ProductCharacteristics(保存其id之一),它会导致以下错误:

org.springframework.dao.InvalidDataAccessApiUsageException:org.hibernate.TransientPropertyValueException:对象引用未保存的临时实例-刷新前保存临时实例:com.orange.obsit.sando.cibinternational.model.persistent.ProductCharacteristic.productVersionElement->com.orange.obsit.sando.cibinternational.model.persistent.ProductVersionElement

你能给我一些建议吗