Setting: I have an object (AProduct) persisted by hibernate in my database. This object references another object (AComponent) stored in a repository. In the database table of the product only the ID of the component should be stored. By loading the product, I want to load the correct component from my repository.
My solution so far is to create a UserType for the component to save only its ID. So far it's easy. Loading the component is also not the big deal because I have the ID.
My problem is how to get a link to the repository in ComponentUserType.
I am using java and Hibernate/Annotations but the solution might be independent.