// id: the primary key
//
Set<String> primaryKeyFields = new HashSet<String>();
if (bean.getPrimkeyField() != null) {
String fieldName = bean.getPrimkeyField();
MappedSuperclass superclass = superclassByField.get(fieldName);
if (superclass == null) {
throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
}
superclass.addField(new Id(fieldName));
mapping.addField(new AttributeOverride(fieldName));
primaryKeyFields.add(fieldName);
} else if ("java.lang.Object".equals(bean.getPrimKeyClass())) {
String fieldName = "OpenEJB_pk";
Id field = new Id(fieldName);
field.setGeneratedValue(new GeneratedValue(GenerationType.AUTO));
mapping.addField(field);
} else if (bean.getPrimKeyClass() != null) {
Class<?> pkClass = null;
try {
pkClass = classLoader.loadClass(bean.getPrimKeyClass());
MappedSuperclass superclass = null;
for (java.lang.reflect.Field pkField : pkClass.getFields()) {
String fieldName = pkField.getName();
int modifiers = pkField.getModifiers();
if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && allFields.contains(fieldName)) {
superclass = superclassByField.get(fieldName);
if (superclass == null) {
throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
}
superclass.addField(new Id(fieldName));
mapping.addField(new AttributeOverride(fieldName));
primaryKeyFields.add(fieldName);
}
}
if (superclass != null) {
superclass.setIdClass(new IdClass(bean.getPrimKeyClass()));
}
} catch (ClassNotFoundException e) {
// todo throw exception
}
}
//
// basic: cmp-fields
//
for (CmpField cmpField : bean.getCmpField()) {
String fieldName = cmpField.getFieldName();
if (!primaryKeyFields.contains(fieldName)) {
MappedSuperclass superclass = superclassByField.get(fieldName);
if (superclass == null) {
throw new IllegalStateException("Primary key field " + fieldName + " is not defined in class " + ejbClassName + " or any super classes");
}
superclass.addField(new Basic(fieldName));
mapping.addField(new AttributeOverride(fieldName));
}
}
return new HashSet<MappedSuperclass>(superclassByField.values());