0

I have a mother Class (SchemaBase) containing a list of CubeBase so i wannt to recuperate that list of CubeBase containing the id of SchemaBase:

public List<CubeBase>listCube(){

    listCubeSchema.addAll(cubeService.listcubeByIdSchema(shmanged.getSchema().getId_schema()));

    return listCubeSchema;

}

and i write this code in managedBean:

public List<CubeBase>listCube(){

        listCubeSchema.addAll(cubeService.listcubeByIdSchema(shmanged.schema.getId_schema()));

        return listCubeSchema;

    }

i get this error:

15:27:24,159 Avertissement [javax.enterprise.resource.webcontainer.jsf.lifecycle] (http-localhost-127.0.0.1-8383-4) #{xmlMan.GenerateXml()}: 
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: esprit.olap.domain.CubeBase.namedSets, no session or session was closed:

this is the Cubebase class:

public class CubeBase implements Serializable{

    /**
     * Private Attribute 
     */
    private static final long serialVersionUID = 1L;




    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id_cube;

    private String name_cube;

    private String description_cube;

    private String caption_cube;

    private boolean visible;

    private boolean cache;

    private boolean enabled;



    @ManyToOne
    private SchemaBase schema;


    @OneToMany (mappedBy="cube",cascade={CascadeType.MERGE,CascadeType.ALL})
    private List<NamedSetBase> namedSets;

    @OneToMany  (mappedBy="cube",cascade={CascadeType.MERGE,CascadeType.ALL})
    private List<MeasureBase> measures;

    @OneToMany  (mappedBy="cube",fetch = FetchType.LAZY)
    private List<DimensionBase> dimensions;

    @OneToOne(cascade=CascadeType.ALL)
    private ViewBase view;

    ....
}

and this is the SchemaClass:

public class SchemaBase implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id_schema;  

    private String name_schema;

    private String description_schema;

    private String measuresCaption_schema;

    private String defaultRole_schema;


    @ManyToOne(fetch=FetchType.LAZY)
    private CatalogBase catalogBase;




    @OneToMany (cascade={CascadeType.MERGE,CascadeType.ALL})
    private List<CubeBase>cubes;

    @OneToMany (cascade={CascadeType.MERGE,CascadeType.ALL}, fetch=FetchType.LAZY)
    private List<ParameterBase>parameters;

    @ManyToMany
    private List<DimensionBase> dimensions;
....}

but she doesn't work to me even i think it's not right so can you help me plz and i don't why the problem is from other class (NamedSet) !!

4 Answers4

1

see this example:

public List<User> getUsers() {
    Query qry = getSession().createQuery("from User u order by upper(u.username)");
    return qry.list();
}
Marin
  • 1,010
  • 1
  • 10
  • 37
0
List<CubeBase> listCube=ent.createQuery(from CubeBase);

To study about writing a query in hibernate refer this link http://www.tutorialspoint.com/hibernate/hibernate_query_language.htm

Selva
  • 1,620
  • 3
  • 33
  • 63
0

This work for me :

final String sql="your hql request";
List<AAA> aaas =  getSession().createQuery(sql).list()
stacky
  • 800
  • 6
  • 18
0

you can get your session with sessionFactory.getCurrentSession() then you use this session for create your queries.