Hi there,
I've got a little improvement for the @IndexedEmbedded annotation in hibernate-search: right now, if the annotated field type is an interface, the @IndexedEmbedded annotation will have no effect on generated lucene indexes, since the referenced type will most likely be unmapped:
Code:
public inerface Parent
{
public Set<Child> getChildren();
public void setChildren(Set<Child> children);
}
public interface Child
{
public Parent getParent();
public void setParent(Parent parent);
}
...
@Entity
@Indexed
class ParentImpl
implements Parent
{
@OneToMany(mappedBy = "parent")
@ContainedIn
private Set<Child> children;
// getters/setters
}
@Entity
@Indexed
public class ChildImpl
implements Child
{
@ManyToOne(targetEntity=ParentImpl.class)
@JoinColumn(...)
@IndexedEmbedded(prefix="parent_")
private Parent parent;
}
Now there is the targetEntity parameter for most @*To* annotations and @org.hibernate.annotations.Target, if none of the former can be used.
Adding the same functionality to hibernate-search annotations is quite easy :
1) Create an IndexedTarget annotation
Code:
package org.hibernate.search.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.Documented;
@Retention( RetentionPolicy.RUNTIME )
@Target( { ElementType.FIELD, ElementType.METHOD } )
@Documented
/**
* Specifies the type of an association (@*ToOne or @Embedded)
*/
public @interface IndexedTarget {
Class value();
}
2) Patch DocumentBuilder to read the new annotation data (patch against current trunk is available upon request)
Thoughts? Should I submit a JIRA issue?
Cheers,
jenner