简体   繁体   中英

Best practice to pass a Domain Class between Grails (Groovy) and Java classes?

I have a Grails service that calls a utility class written in Java. The Java utility class would need to use and manipulate the Domain Classes written in Grails, which are passed into it. Also eventually, the output needs to be a Domain Class in Grails and not a java object.

So basically: Grails Domain Class input -> manipulated by Java utility class -> Grails Domain Class output to Grails Service and forward to Controller.

What would be the best practice to handle the above? Should I write identical value objects in Java? I guess I cannot manipulate the Grails Domain Classes directly within the Java class?

You can send it to Java classes directly.

One thing to note is that you should be aware of your objects detaching out of the current Hibernate session. If it's the case, you may require to attach it back (using merge() for example) to another Hibernate session before further proceed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM