Hibernate and proxied objects

asked 2019-10-03 17:21:29 +0800

pavelEW gravatar image pavelEW
53 2

Hello! I've got a problem and maybe there is a solution for it. Let's say I have an entity called Order, and it has a One-To-One association with entity Customer. I have an OrderCRUDVM class, where I have the following

private Order selectedOrder;
private Order selectedOrderProxy;

and then

selectedOrder = order;
selectedOrderProxy = ProxyHelper.createFormProxy(selectedOrder, Order.class);

and the following thing on my zul:

<div form="@id('fx') @init(vm.selectedOrderProxy) @load(vm.selectedOrder) @save(vm.selectedOrder, before={'onSave', 'onSaveClose'})">

after that I have a @Command which sets a Customer to selectedOrderProxy and runs a hql query, which checks for other orders for same customer. When I try to pass a proxied customer to a hibernate query I get the following error:

org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: Customer

Any ideas on how it should be done?

delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted

answered 2019-10-04 15:11:03 +0800

cor3000 gravatar image cor3000
5225 2 7
ZK Team

First I would check if this problem is related to ZK. Did you try this without the form proxy object? Does it behave differently?

This was the first search result I found for your error message (maybe it's related):


If you need the original object (the non proxied version) you can get it by calling


Also, if you don't need to edit the fields of the Customer object in your form, you can mark the getCustomer() method as @Transient. This will prevent a proxy to be generated around the Customer object, when added to the Order-proxy.

If this doesn't help or the case is more complex please contact ZK directly for support.

link publish delete flag offensive edit


Hi cor3000, that is exactly ZK's problem. If i do something like this: customer = customerService.getCustomer(selectedOrderProxy().getCustomer().getUid()); it works. I'll try your suggestions in a few minutes and let you know if it works :)

pavelEW ( 2019-10-04 15:45:14 +0800 )edit

So, I tried to get the original object. It worked, but not for all objects in Order. Some of them are still proxied. Using @Transient won't work for me because I have maven multimodule project, all the entities are in backend, ZK is in front and I don't want to include ZK into backend projects.

pavelEW ( 2019-10-04 16:52:41 +0800 )edit

if the standard functions aren't sufficient we'll have to set up a dedicated test scenario, I guess that somewhat extends the scope of this forum, unless you can share a simple runnable project (maven/gradle) so I can instantly run/test if there are alternative ways to avoid the problem

cor3000 ( 2019-10-04 18:09:27 +0800 )edit

I'll try to create a simple project to reproduce this problem, but it will take some time. I'll try to reach you on a next week if it fits to you.

pavelEW ( 2019-10-04 19:02:04 +0800 )edit

I'll try to help assist if time allows.

cor3000 ( 2019-10-07 12:35:19 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2019-10-03 17:21:29 +0800

Seen: 12 times

Last updated: Oct 04 '19

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More