Hello,
I'm trying to implement a system which is defined in an API, but JPA entities won't be found by hibernate. I'm using a JBoss AS6 server by the way.
The api layer describes domain subjects and actions to take over them. For example an applicant will submit an application for processing and expect and answer with messages out of this processing.
Code:
public interface Application {
Applicant getApplicant();
void setApplicant(Applicant applicant);
}
And the implementation is as follows
Code:
@Entity
public class ApplicationJPA implements Application {
private ApplicantJPA applicant;
public Applicant getApplicant() { return this.applicant; }
public void setApplicant(Applicant applicant) { this.applicant = applicant; }
}
@Entity
public class ApplicantJPA implements Applicant {
}
But this code causes hibernate to complain it's expecting an ApplicantJPA and not an Applicant with the following exception
Code:
DEPLOYMENTS IN ERROR:
Deployment "persistence.unit:unitName=test.war#testPU" is in error due to the following reason(s): org.hibernate.AnnotationException: @OneToOne or @ManyToOne on ApplicationJPA.applicant references an unknown entity: Applicant
Deployment "<UNKNOWN jboss.j2ee:jar=test.war,name=ApplicationJPADAO,service=EJB3>" is in error due to the following reason(s): ** UNRESOLVED Demands 'persistence.unit:unitName=test.war#testPU' **
So, I've change them into generics. The Application interface now looks like
Code:
public interface Application<T extends Applicant> {
T getApplicant();
void setApplicant(T applicant);
}
This is causing some problems with collections and with lengthly declarations since here I'm only using one attribute, Applicant, but as you may guess there are many more. So, I changed to an in-line approach
Code:
public interface Application {
<T extends Applicant> T getApplicant();
<T extends Applicant> void setApplicant(T applicant);
}
But this causes me confusion as to how to declare the attribute in the JPA implementation
Code:
@Entity
public class ApplicationJPA implements Application {
private ApplicantJPA applicant; // This causes the set method to fail
public Applicant getApplicant() { return this.applicant; }
public void setApplicant(Applicant applicant) { this.applicant = applicant; }
}
In your experience what would be a better approach and/or how to correct the technique.
Thanks in advance