Created
July 13, 2017 19:01
-
-
Save emanoelqueiroz/9676683b7d9c118a5aa0c1b9befc0f7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void setParentId(T parentEntity, List<T> listEntity) { | |
| try { | |
| Long parentId = null; | |
| for (Field field : parentEntity.getClass().getDeclaredFields()) { | |
| if (field.getDeclaredAnnotation(SequenceId.class) == null) { | |
| continue; | |
| } | |
| PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(parentEntity.getClass(), field.getName()); | |
| parentId = (Long) pd.getReadMethod().invoke(parentEntity); | |
| break; | |
| } | |
| if (parentId == null) { | |
| return; | |
| } | |
| for (T entity : listEntity) { | |
| for (Field field : entity.getClass().getDeclaredFields()) { | |
| if (field.getDeclaredAnnotation(ParentId.class) == null) { | |
| continue; | |
| } | |
| PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(entity.getClass(), field.getName()); | |
| pd.getWriteMethod().invoke(entity, parentId); | |
| break; | |
| } | |
| } | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment