I'm coming back to Java after a few years away and this is my 2nd day looking at hibernate and don't fully understand it yet.
I have the following criteria which is performing a join:
Criteria cr = s.createCriteria(Bla.class, "bla");
cr.setFetchMode("bla.nodePair", FetchMode.JOIN);
cr.createAlias("bla.nodePair", "node_pair");
cr.add(Restrictions.in("bla.blaName", (List<Bla>) getBlas()));
ProjectionList columns = Projections.projectionList()
.add(Projections.property("node_pair.priNode"))
.add(Projections.property("bla.blaName"))
.add(Projections.property("node_pair.secNode"))
.add(Projections.property("bla.port"));
cr.setProjection(columns);
List<Object[]> list = cr.list(); // Exception occurs here
This is creating as far as I can tell a valid SQL query and exactly what i'm after.
However, when I try to generate a list of results cr.list(); I get:
java.lang.ClassCastException: com.some.package.domainobject.Bla cannot be cast to java.lang.String
How should I construct my List. Any pointers much appreciated.
Bla? Did you put it there? You could be trying to read a different object out of the database and that's tripping you up.