I am working on an abstract model to represent a variety of complex business processes based on event registration. For that purpose, I want to be able to persist Java8 Function objects using the newest version of Hibernate, such as
@Entity
public class Foo {
private Runnable onUpdate = () -> System.out.println("worked");
private java.util.function.Function<String, String> identity = s -> s;
// imagine bean-compliant getter and setter
}
Persisting method references is not an option, since partial method application during runtime before setting a callback is a requirement.
Just trying above code leads to the following exception:
org.hibernate.MappingException: Could not determine type for: java.lang.Runnable ...
Is there any way to persist function objects that match a fixed functional interface such as Runnable
? And if not, what alternative strategies are available?
EDIT concerning the XY-problem:
I want to be able to associate methods in an object with some hibernate entity's
PostUpdate callback during runtime, while letting the user supply all arguments which the hibernate callback can not supply. For example, I have an entity @Entity public class Bar
and another controller class with a method void foo(Bar new, int i)
. Now, every time a specific instance of Bar
is updated in the database, I want it to call foo
with the updated object and a parameter i
, which is specified by the user during current or some previous runtime while associating the foo-Event
with the Bar
instance.
Most importantly, I want to persist this runtime association using Hibernate, keeping a reference to the method, the object the method belongs to and all parameters supplied during association. Then, on server startup, as soon as the controller object is loaded it listens to changes made to the entity instance.