We're updating the issue view to help you get more done. 

DocumentId ignored in case of EmbeddedId

Description

When a class contains both a @DocumentId and an @EmbeddedId set at different fields, Hibernate Search should use the DocumentId field.
However, I'm noticing in 4.1.0Beta2 that in this case, the EmbeddedId field is used. In my case this leads to a

org.hibernate.search.bridge.BridgeException: Exception while calling bridge#objectToString
class: nl.project.model.NetworkCandidateLink
field bridge: id
at org.hibernate.search.bridge.util.impl.ContextualExceptionBridge.buildBridgeException(ContextualExceptionBridge.java:78)
at org.hibernate.search.bridge.util.impl.ContextualException2WayBridge.objectToString(ContextualException2WayBridge.java:84)
at org.hibernate.search.batchindexing.impl.EntityConsumerLuceneWorkProducer.index(EntityConsumerLuceneWorkProducer.java:164)
at org.hibernate.search.batchindexing.impl.EntityConsumerLuceneWorkProducer.indexAllQueue(EntityConsumerLuceneWorkProducer.java:134)
at org.hibernate.search.batchindexing.impl.EntityConsumerLuceneWorkProducer.run(EntityConsumerLuceneWorkProducer.java:105)
at org.hibernate.search.batchindexing.impl.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:112)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: nl.project.model.NetworkCandidateLinkId cannot be cast to java.lang.String
at org.hibernate.search.bridge.builtin.StringBridge.objectToString(StringBridge.java:39)
at org.hibernate.search.bridge.builtin.impl.TwoWayString2FieldBridgeAdaptor.objectToString(TwoWayString2FieldBridgeAdaptor.java:48)
at org.hibernate.search.bridge.util.impl.ContextualException2WayBridge.objectToString(ContextualException2WayBridge.java:77)
... 7 more

I'm failry certain this was working correctly in 3.x

The class configuration is as follows:
@Entity
@Table
@AssociationOverrides({
@AssociationOverride(name = "pk.network",
joinColumns = @JoinColumn(name = "nwId")),
@AssociationOverride(name = "pk.candidate",
joinColumns = @JoinColumn(name = "cId"))
})
@Indexed
public class NetworkCandidateLink implements Serializable{

private NetworkCandidateLinkId pk = new NetworkCandidateLinkId();

@EmbeddedId
public NetworkCandidateLinkId getPk() {
return pk;
}

public void setPk(NetworkCandidateLinkId pk) {
this.pk = pk;
}

@DocumentId
@Transient
public String getId(){
return pk.getCandidate().getId() + "_" + pk.getNetwork().getId();
}

Environment

None

Status

Assignee

Sanne Grinovero

Reporter

Marc Schipperheyn

Suitable for new contributors

Yes, likely

Components

Affects versions

4.0.0.Final
4.1.0.Beta2

Priority

Critical