Unable to guess FieldBridge for order in org.openmrs.Order

Tags: #<Tag:0x00007f8284df9e78> #<Tag:0x00007f8284df9b58> #<Tag:0x00007f8284df9a40>

Hi devs,

I’m trying to write some unit tests for API of this module. I’ve used Order entity as one-to-one identifying dependency in LabTest class.

On executing CommonLabTestServiceTest as JUnit, I’m thrown this exception, I have no idea what FieldBridge is, and a quick SOF search indicates hibernate search version incompatibility; this is unlikely an issue since I’m using Openmrs defaults.

Any clues?

The issue was resolved by changing the way we define One-to-one mapping. Previously, I was trying to create mapping using:

public class LabTest extends BaseCustomizableData<LabTestAttribute> implements java.io.Serializable, Attributable<LabTest> {

@Id
@OneToOne(optional = false)
@JoinColumn(name = "test_order_id")
private Order order;
}

I changed to:

@Id
private Integer testOrderId;
@OneToOne(optional = false)
@PrimaryKeyJoinColumn(name = "testOrderId")
@JoinColumn(name = "test_order_id")
private Order order;

… by explicitly defining the primary key object. There’s a bug in earlier versions of hibernate 4.x, which tries to find a bridging entity for One-to-one mapping.

Thanks to @maimoonak for the tip.