mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-08 21:38:21 +00:00
Update SnapAdmin version and improve foreign key mapping logic
Bumped the `VERSION` constant from 0.4.1 to 0.6.2. Enhanced the `mapForeignKeyType` method to scan the entire class hierarchy for `@Id` annotations, ensuring better support for inherited entity structures.
This commit is contained in:
parent
61ff240456
commit
9963f504c5
@ -89,7 +89,7 @@ public class SnapAdmin {
|
|||||||
|
|
||||||
private boolean authenticated;
|
private boolean authenticated;
|
||||||
|
|
||||||
private static final String VERSION = "0.4.1";
|
private static final String VERSION = "0.6.2";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the SnapAdmin instance by scanning the `@Entity` beans and loading
|
* Builds the SnapAdmin instance by scanning the `@Entity` beans and loading
|
||||||
@ -398,18 +398,25 @@ public class SnapAdmin {
|
|||||||
private DbFieldType mapForeignKeyType(Class<?> entityClass) {
|
private DbFieldType mapForeignKeyType(Class<?> entityClass) {
|
||||||
try {
|
try {
|
||||||
Object linkedEntity = entityClass.getConstructor().newInstance();
|
Object linkedEntity = entityClass.getConstructor().newInstance();
|
||||||
Class<?> linkType = null;
|
Class<?> clazz = linkedEntity.getClass();
|
||||||
|
Field idField = null;
|
||||||
|
|
||||||
for (Field ef : linkedEntity.getClass().getDeclaredFields()) {
|
// 상속 계층 전체를 스캔하여 @Id 필드 탐색
|
||||||
if (ef.getAnnotationsByType(Id.class).length != 0) {
|
while (clazz != null && clazz != Object.class) {
|
||||||
linkType = ef.getType();
|
for (Field ef : clazz.getDeclaredFields()) {
|
||||||
|
if (ef.getAnnotationsByType(jakarta.persistence.Id.class).length != 0) {
|
||||||
|
idField = ef;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (idField != null) break;
|
||||||
|
clazz = clazz.getSuperclass();
|
||||||
|
}
|
||||||
|
|
||||||
if (linkType == null)
|
if (idField == null)
|
||||||
throw new SnapAdminException("Unable to find @Id field in Entity class " + entityClass);
|
throw new SnapAdminException("Unable to find @Id field in Entity class hierarchy: " + entityClass);
|
||||||
|
|
||||||
return DbFieldType.fromClass(linkType).getConstructor().newInstance();
|
return DbFieldType.fromClass(idField.getType()).getConstructor().newInstance();
|
||||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||||
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
||||||
throw new SnapAdminException(e);
|
throw new SnapAdminException(e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user