1- you build four entity beans with the PKs and FKs defined (with relations between them).
2- you should config your ejb-jar.xml to have references to entity from session bean.
3- Implement your session bean method like this :
public String doInsert (any parameter) {
// Configure your JNDI Properties
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY,
" org.jnp.interfaces.NamingContextFactory");
environment.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
environment.put(Context.PROVIDER_URL , "jnp://localhost:1099");
InitialContext ctx = null;
try {
ctx = new InitialContext(environment);
} catch (NamingException ex) {
}
// Lookup entity beans home interfaces (these are configured in <ejb-local-ref> or <ejb-ref> in ejb-jar.xml)
Object result1=null, result2 = null, result3=null, result4 = null;
try {
result1 = ctx.lookup("java:comp/env/ejb/FirstHome");
result2 = ctx.lookup("java:comp/env/ejb/SecondHome");
result3 = ctx.lookup("java:comp/env/ejb/ThirdHome");
result4 = ctx.lookup("java:comp/env/ejb/ForthHome");
} catch (NamingException ex1) {
}
FirstHome firsthome=(FirstHome) result1;
SecondHome secondhome=(SecondHome) result2;
ThirdHome thirdhome=(ThirdHome) result3;
ForthHome forthhome=(ForthHome) result4;
try {
First f=firsthome.create(field_A , field_B);
Second s= secondhome.create (field_C, field_D, field_E);
Third t= thirdhome.create(field_F, field_G);
Forth fo= forthhome.create(field_H, field_J);
fo.setFirst(f);
fo.setSecond(s);
fo.setThird(t);
} catch (CreateException ex2) {
}
return "";
}
Which you can get parameters value from a DTO or HashMap or ...