Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用hibernate加载实体中的所有内部对象_Java_Hibernate - Fatal编程技术网

Java 如何使用hibernate加载实体中的所有内部对象

Java 如何使用hibernate加载实体中的所有内部对象,java,hibernate,Java,Hibernate,在我的项目hibernate中,我使用hibernate将数据库表加载到具有其他内部关联对象的对象(实体)中。例如: application = getSession().createQuery("from ApplicationEntity appEntity" + " join fetch appEntity.routesEntity rEntity" + " join fetch appEntity.viewsE

在我的项目hibernate中,我使用hibernate将数据库表加载到具有其他内部关联对象的对象(实体)中。例如:

      application = getSession().createQuery("from ApplicationEntity appEntity"
                + " join fetch appEntity.routesEntity rEntity"
                + "  join fetch appEntity.viewsEntity vEntity"
                + "  join fetch rEntity.urlEntity uEntity"
                + "  join fetch rEntity.perrmisioEntity pEntity"
                   etc ......... to get alot of joins
         );
        commit();
类应用程序性:

 class ApplicationEntity{

    private RoutesEntity routesEntity;

    private ViewsEntity viewsEntity;

    //....... some other class body

 }
类路由实体:

 class RoutesEntity{

       private UrlEntity urlEntity;

       private PermissionEntity permmisionEntity;

 }
类视知觉:

  class ViewsEntity{

        private ContentEntity contentsEntity;

        private LayoutEntity layoutEntity;


  }
现在我想使用HQL完全加载对象ApplicationEntity(带有内部对象)。但避免使用连接获取i HQL,例如:

      application = getSession().createQuery("from ApplicationEntity appEntity"
                + " join fetch appEntity.routesEntity rEntity"
                + "  join fetch appEntity.viewsEntity vEntity"
                + "  join fetch rEntity.urlEntity uEntity"
                + "  join fetch rEntity.perrmisioEntity pEntity"
                   etc ......... to get alot of joins
         );
        commit();
可以使用简单的

     application = getSession().createQuery("from ApplicationEntity");

但在惰性模式下,但像渴望模式一样工作

第一次访问标记为“惰性”的属性将获取它(或抛出著名的“无会话或会话已关闭”异常)。 因此,只需创建如下函数:

public void fetchAll(ApplicationEntity a) {

          a.getRoutesEntity().getUrlEntity();
          ..
          a.getViewsEntity().getLayoutEntity();

}

从hibernate会话内部调用它。

您的问题是什么?如何使用HQL完全加载对象应用程序属性(带有内部对象)。但是避免使用join fetch,这是hibernate中的默认行为,除非您将属性设置为显式地延迟加载。