Update BasicDAO.java

I use polymorphic entities in one collection. I wrote createPolymorphicQuery method to avoid ClassCastException.