@Access(AccessType.PROPERTY) with @OneToMany not working


#1

I can’t find a working example in the web using @Access(AccessType.PROPERTY) in combination with bi-directional @OneToMany / @ManyToOne associations.

I am running a desktop application with Spring Boot v2.0.4.RELEASE, Spring v5.0.8.RELEASE and Hibernate Core {5.2.17.Final} , Java 1.8.0_161

I have a Entity class UserRequirement. Instances of this class will be processed in a certain workflow. During this process it will change it’s condition (state) a few times. Later I need to evaluate the process pace, therefore I need to keep all condition changes in a List.

I have one design constraint: Since I want to use ObservableLists in my entities classes within JavaFX, originally I had a problem with the dedicated List implementation and injection over reflection that Hibernate is using by default. Therefore I decided to have my Entity classes annotated with @Access(AccessType.PROPERTY), because I want to enforce that Hibernate uses my getter and setter methods and not reflection.

UserRequirement and UserRequirementStatus have a bi-directional relation. The problem is that when a UserRequirement object is saved, the UserRequirementStates in the list are not saved.

Thank you in advance.

The entire code and more information can be found here :
Stackoverflow link


#2

You’re saying the access property is the issue. Does it work properly when the annotations are on the fields?

Could you create a self contained test case outside of Spring using our test case template: https://github.com/hibernate/hibernate-test-case-templates/tree/master/orm/hibernate-orm-5 ?


#3

As I worte on Stackoverflow the problem is related with the UserRequirement method
public void setConditions(List<;UserRequirementStatus> newConditions);
is should be

public void setConditions(List<;UserRequirementStatus> newConditions){
this.conditions = newConditions;
}

#4

Hello gsmet. Thank you for the feedback. Unfortunately I don’t understand what you want me to do with these classes, since I am rather the frontend guy - that is why I wanted to use Spring and Hibernate, as I have little understanding of backend design and programming. Is there somewhere a Readme, tutorial or alike of what I need to do?


#5

Hello dreab8. Thank you for your feedback. You’re right, and you’re wrong. The code works, but the constraint that I need to get ObservableLists from the getter methods is not taken care of. Hence, I get a ClassCastException when I try to use the Entity in a JavaFX context. That was the reason why I copied the List in the setter into the ObservableList. But from this observation, that copying the data into the ObservableList causes the issue, can we derive a solution? Thank you in advance.


#6

@a.levin Just follow this article about how to write a Hibernate test case. It’s actually even easier than writing Spring or Hibernate code in your application.