-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: ClassBridge - Embedded and ContainedIn
PostPosted: Thu Feb 04, 2016 1:15 pm 
Beginner
Beginner

Joined: Wed Aug 06, 2014 10:53 am
Posts: 30
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


Top
 Profile  
 
 Post subject: Re: ClassBridge - Embedded and ContainedIn
PostPosted: Mon Feb 08, 2016 8:25 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi darioc,
in your example the entity DangerousEventLinkedProfileID is marked as @ContainedIn -> DangerousEvent which simply means that on a change, the indexing process needs to refresh the Lucene Document for the DangerousEvent type.
The DangerousEvent however is marked with a @ClassBridge! The ClassBridge implementation completely overrides the indexing process.

So in your example it's correct to have the @ContainedIn marker to trigger indexing via your custom ClassBridge, but your implementation CustomIndexingClassBridge.class is responsible for adding all fields to the Lucene Document, even the embedded ones.

I hope we'll have time for implementing a combination of ClassBridge && annotations in Hibernate Search 6, but currently it's an either-or strategy.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.