I have a one-to-many relation and want to use all the CascadeType
for except the CascadeType.REMOVE
. I did this:
@OneToMany(cascade= {CascadeType.DETACH, CascadeType.MERGE,
CascadeType.PERSIST, CascadeType.REFRESH})
Since I will be using it several places in the project I wanted to write a method to return all the other CascadeType
except REMOVE
.
For example:
public class Helper {
public /*I also do not know the return type*/ myMethod(CasccadeType x) {
// return all the CascateType except x
}
}
Then I want to call it from an annotation
public class Model{
@Autowwired
private Helper helper;
...
@OneToMany(cascade = helper.myMethod(CascadeType.REMOVE))
@JoinColumn(...)
private field name;
...
}
I'm fairly new to enums and can't seem to find any solutions for this. I don't know if JPA
allows it or not. Also, if it's allowed, will it be the best practice?
I'm using spring
, hibernate-5.4
and java-1.8
. Please suggest how can I do it. Thanks in advance.
Please login or Register to submit your answer