playframework 1.2.x 中的save()和JPA的persist方法在处理级联时有何不同

glowd
博客专家认证
2013-10-26 11:49:39
playframework 1.2.x 中的save()和JPA的persist方法在处理级联时有何不同?
我查看了play 的源码,还是不甚理解,请高人解释一下
...全文
635 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
glowd 2013-10-29
  • 打赏
  • 举报
回复
有使用文档,没有源码分析文档
引用 5 楼 defonds 的回复:
有没有文档呢
Defonds 2013-10-29
  • 打赏
  • 举报
回复
有没有文档呢
glowd 2013-10-28
  • 打赏
  • 举报
回复
大侠啊,我想知道saveAndCascade()方法有何用?多谢指教
我的波塞冬 2013-10-28
  • 打赏
  • 举报
回复
不知道
teemai 2013-10-28
  • 打赏
  • 举报
回复
play morphia save??
glowd 2013-10-28
  • 打赏
  • 举报
回复
有哪位java大神能指教一下play封装的save(),有什么作用吗?还望大神指教 public void _save() { if (!em().contains(this)) { em().persist(this); PlayPlugin.postEvent("JPASupport.objectPersisted", this); } avoidCascadeSaveLoops.set(new ArrayList<JPABase>()); try { saveAndCascade(true); } finally { avoidCascadeSaveLoops.get().clear(); } try { em().flush(); } catch (PersistenceException e) { if (e.getCause() instanceof GenericJDBCException) { throw new PersistenceException(((GenericJDBCException) e.getCause()).getSQL()); } else { throw e; } } avoidCascadeSaveLoops.set(new ArrayList<JPABase>()); try { saveAndCascade(false); } finally { avoidCascadeSaveLoops.get().clear(); } } private void saveAndCascade(boolean willBeSaved) { this.willBeSaved = willBeSaved; if (avoidCascadeSaveLoops.get().contains(this)) { return; } else { avoidCascadeSaveLoops.get().add(this); if (willBeSaved) { PlayPlugin.postEvent("JPASupport.objectUpdated", this); } } // Cascade save try { Set<Field> fields = new HashSet<Field>(); Class clazz = this.getClass(); while (!clazz.equals(JPABase.class)) { Collections.addAll(fields, clazz.getDeclaredFields()); clazz = clazz.getSuperclass(); } for (Field field : fields) { field.setAccessible(true); if (Modifier.isTransient(field.getModifiers())) { continue; } boolean doCascade = false; if (field.isAnnotationPresent(OneToOne.class)) { doCascade = cascadeAll(field.getAnnotation(OneToOne.class).cascade()); } if (field.isAnnotationPresent(OneToMany.class)) { doCascade = cascadeAll(field.getAnnotation(OneToMany.class).cascade()); } if (field.isAnnotationPresent(ManyToOne.class)) { doCascade = cascadeAll(field.getAnnotation(ManyToOne.class).cascade()); } if (field.isAnnotationPresent(ManyToMany.class)) { doCascade = cascadeAll(field.getAnnotation(ManyToMany.class).cascade()); } if (doCascade) { Object value = field.get(this); if (value == null) { continue; } if (value instanceof PersistentMap) { if (((PersistentMap) value).wasInitialized()) { for (Object o : ((Map) value).values()) { if (o instanceof JPABase) { ((JPABase) o).saveAndCascade(willBeSaved); } } } continue; } if (value instanceof PersistentCollection) { if (((PersistentCollection) value).wasInitialized()) { for (Object o : (Collection) value) { if (o instanceof JPABase) { ((JPABase) o).saveAndCascade(willBeSaved); } } } continue; } if (value instanceof HibernateProxy && value instanceof JPABase) { if (!((HibernateProxy) value).getHibernateLazyInitializer().isUninitialized()) { ((JPABase) ((HibernateProxy) value).getHibernateLazyInitializer().getImplementation()).saveAndCascade(willBeSaved); } continue; } if (value instanceof JPABase) { ((JPABase) value).saveAndCascade(willBeSaved); continue; } } } } catch (Exception e) { throw new UnexpectedException("During cascading save()", e); } }

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧