The @ContainedIn annotation doesn't work when I execute the Entitymanager.persist(): the fields regarding the "embedded field" are empty!
On update record indexing is correct.
The following code describe my domain:
Code:
public class Profile{
private String surname;
...
}
@ClassBridge(name = "customIndexingClassBridge", impl = CustomIndexingClassBridge.class)
public class DangerousEvent{
@OneToMany(mappedBy = "compositeKey.dangerousEvent", fetch = FetchType.LAZY)
Set<DangerousEventLinkedProfile> profils;
...
}
@ClassBridge(name = "customIndexingClassBridge", impl = CustomIndexingClassBridge.class)
public class DangerousEventLinkedProfile{
@Embedded
private DangerousEventLinkedProfileID compositeKey = new DangerousEventLinkedProfileID();
private String tag;
...
}
@Embeddable
public class DangerousEventLinkedProfileID{
@ContainedIn
@ManyToOne
DangerousEvent dangerousEvent,
@ContainedIn
@ManyToOne
Profile profile;
...
}
// TEST PROCEDURES
Code:
..
@PersistenceContect
EntityManager em;
// DONT WORK
public void wontWork(){
DangerousEvent dangerousEvent = new DangerousEvent();
Profile profile = new Profile();
profile.setSurname('test surname');
DangerousEventLinkedProfile link = new DangerousEventLinkedProfile();
link.getCompositeKey().setDangerousEvent(dangerousEvent);
link.getCompositeKey().setProfile(profile);
em.persist(link);
// The index misses "surname" field;
}
// WORK WELL
public void workAndIndexCorrectly(){
DangerousEventLinkedProfile link = em.find(DangerousEventLinkedProfile.class , existingUUID);
link.tag = 'test';
em.merge(link);
// Index fills "surname" field;
}
Do you have any idea what could be the problem? I'm doing some mistake?
dario