asked
2021-03-04 17:57:55 +0800
pavelEW 55 ● 4 Hello,
I have a bidirectional association in my model:
Product OneToMany Price
Price OneToOne Product
When I try to add a new price on a form and then save it I get a StackOverflow error, here is stacktrace from my project:
at my.model.Ware_$$_jvstd2_b5.submitToOrigin(Ware_$$_jvstd2_b5.java)
at org.zkoss.bind.proxy.BeanProxyHandler.invoke(BeanProxyHandler.java:126)
at my.model.Price_$$_jvstd2_b9.submitToOrigin(Price_$$_jvstd2_b9.java)
at org.zkoss.bind.proxy.AbstractCollectionProxy.submitToOrigin(AbstractCollectionProxy.java:233)
at org.zkoss.bind.proxy.BeanProxyHandler.invoke(BeanProxyHandler.java:126)
at org.zkoss.bind.proxy.FormProxyHandler.invoke(FormProxyHandler.java:163)
at my.model.Ware_$$_jvstd2_b5.submitToOrigin(Ware_$$_jvstd2_b5.java)
at org.zkoss.bind.proxy.BeanProxyHandler.invoke(BeanProxyHandler.java:126)
at my.model.Price_$$_jvstd2_b9.submitToOrigin(Price_$$_jvstd2_b9.java)
at org.zkoss.bind.proxy.AbstractCollectionProxy.submitToOrigin(AbstractCollectionProxy.java:233)
Here is a quick fiddle to reproduce this error: https://zkfiddle.org/sample/h7t36l/1-Another-new-ZK-fiddle
Press "Add price" button and then "Save".
Some explanations:
In class Logic.java on 25 and 26 strings you'll find
price = product.getPrices().stream().findFirst().get();
price.setProduct(product);
I do this to get a proxied instance of Price, if I keep using an original object, then I get a Hibernate error, that my instance is transient and can't be saved.
In debug mode I see that after submitting all values to original price still contains proxied object of Ware (Product).
If I put an original ware object to original price object, then I get another one proxy instance of ware in price.
Any ideas?