in google-cloud-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/schema/SchemaUtils.java [97:122]
public static Set<SpannerEntityFieldKey> resolveIdFields(Class<?> entity, Set<Class<?>> resolved)
throws SecurityException {
// If the class has a field marked as the embedded id, that is the composite key.
Field embeddedId = getEmbeddedId(entity);
Class<?> compositeKeyClazz = embeddedId != null ? embeddedId.getType() : entity;
// All fields are included in the composite key if the is is an embedded id.
boolean keepAllFields = embeddedId != null || entity.getAnnotation(Embeddable.class) != null;
Set<SpannerEntityFieldKey> ids = new HashSet<>();
for (Field field : SpannerKeyFieldIterator.iterable(compositeKeyClazz)) {
if (keepAllFields || field.getAnnotation(Id.class) != null) {
Class<?> fieldType = field.getType();
if (fieldType.getAnnotation(Embeddable.class) != null && !resolved.contains(fieldType)) {
// if the field is Embeddable and unresolved, recurse
resolved.add(entity);
ids.addAll(resolveIdFields(fieldType, resolved));
} else {
ids.add(new SpannerEntityFieldKey(fieldType, field.getName()));
}
}
}
return ids;
}