Question: This query:

```
Query query = HibernateUtil.getSessionFactory().getCurrentSession().createQuery("SELECT substring(a.account, 1, 6), a.ref, b.event_id, substring(a.admin, 1, :adminLength) FROM Parent a, Child b WHERE b.joinString = a.joinString AND b.event_id=:eventId AND substring(a.admin, 1, :adminLength) LIKE :admin AND a.date BETWEEN :from AND :to");

```

Produces a SQL statement that works in MySQL.

However, when I loop through the Child `List` I get `java.lang.ClassCastException` on the line `for (int j = 0; j < allParent.get(i).getAllChild().size(); j++) {` of this loop:

```
for (int i = 0; i < allParent.size(); i++) {
    System.out.println(allParent.get(i));
    for (int j = 0; j < allParent.get(i).getAllChild().size(); j++) {
           System.out.println("Child: " + allParent.get(i).getAllChild().get(j).getID());
    }
    HibernateUtil.getSessionFactory().getCurrentSession().flush();
    HibernateUtil.getSessionFactory().getCurrentSession().clear();
}

```

**Parent.hbm.xml**

```
<bag name="allChild" table="child" inverse="true" lazy="true" fetch="select">
    <key property-ref="surname">
        <column name="surname" not-null="true" />
    </key>
    <one-to-many class="com.test.Child" />
</bag>

```

Is there a way I can run this statement using `Criteria` (or something else) instead and have it populate both `allParent` `List` and `allChild` `List` linked to each `Parent` within `allParent`?

Answer: 
Calling `setContentView` several times will simply replace whatever view you set before. So what you want to do is create a root view that contains the multiple views you want to add and set the root view to your Activity with `setContentView`. Your second example with the `FrameLayout` is a good approach.
Your approach is valid at some extent. but its nice practice to call the setcontentView() once in activity.

this is because it will be very easy to maintain the Activity life cycle and reduce the app crash due to layout leak.

I personally call the setcontentView() once. I define all the layout in single XML file. Afterwords I call `setVisibility(View.VISIBLE)` and `setVisibility(View.INVISIBLE)` or `setVisibility(View.GONE)` to show or hide any particular layout containing my certain views.

**Edit**

Also its very easy to adjust the layout in XML because you can use simple drag and drop and If you are using `relativeLayout` then it will be very easy to place any view any where. but in Java code its some how difficult to place the views on your desired position

Hope this helps :)