I have a database that can have different types of relatinships based upon what data was updated during the last business transaction. An example would be in a policy writing application. The main table contains generic policy level information and there are related tables containing information such as the agent's information and the insureds information. When the first transaction is issued all of the tables are populated, however on subsequent transactions only the tables that have updates are persisted to the database. What I am trying to do now is to create classes implementing JPA that define the relationships between the tables as one-to-one. I would then like to implement custom loaders for each of the relationships to ensure that each time I retrieve the policy entity I can be able to retrieve the most recent version of the corresponding tables. Does anyone know how to implement this logic? I have tried using @NamedNativeQuery
and using HQL, but in both instances it tells me that a column name I am specifying doesn't exist.
Any assistance would be greatly appreciated.
Code has been provided below to help illustrate what I am doing.
@Entity
@NamedNativeQuery(name = "loadLatestBilling",
query = "Select {i.*} from TransactionSummary as ts outer join BillingInfo i on i.systemAssignId=ts.systemAssignId where ts.systemAssignId=:systemAssignId and i.transSeqNo<=:transSeqNo order by i.systemAssignId, i.transSeqNo DESC",
resultClass = BillingInfo.class)
public class CoTransactionSummary implements java.io.Serializable,
CdbCoTransactionSummary {
@OneToOne(targetEntity = BillingInfo.class, fetch = FetchType.LAZY)
@org.hibernate.annotations.NotFound(action = org.hibernate.annotations.NotFoundAction.IGNORE)
@Loader(namedQuery = "loadLatestBilling")
public BillingInfo getBillingInfo() {
return billingInfo;
}
public void setBillingInfo(BillingInfo billingInfo) {
this.billingInfo= billingInfo;
}
}
In the above example the SystemAssignId would be common between all of the records pertaining to that entity. The transSeqNo would be incremented for each successive transaction and thus the custom loader would look for the highest value associated with the systemAssignId.
Thank you very much for any assistance that you can provide.