Hello everyone,
I've reverse engineered a class using eclipse's plugin.
The result are the following files:
hbm.xml:
http://dpaste.com/205097/java class:
http://dpaste.com/205111/java class:
http://dpaste.com/205113/ (btw, why does hibernate create this class too?)
When getting a List by:
List utpList = session.createCriteria(UsuarioTerritorioPerfil.class).setProjection(
Projections.projectionList()
.add(Projections.property("territorio"))
.add(Projections.property("perfil"))
).add(Restrictions.eq("usuario",user)).list();
}catch (SQLGrammarException e) {
this.setMsg("Criteria Error: " + e.getSQL());
return msg;
}
I get the classcast exception when iterating through the elements:
java.util.Iterator<UsuarioTerritorioPerfil> i = utpList.iterator();
JSONObject u = new JSONObject();
//UsuarioTerritorioPerfil utp;
while (i.hasNext()){
try {
/*
* Long t=i.next().getTerritorio().getId(); Can't do this, ClassCastException!
* i.next() is an instance of Object and cannot cast it...
*/
u.put("id", user.getId());
u.put("territory","t");
u.put("profile","p");
objectList.put(u);
i.next();
}
catch (Exception e) {
e.printStackTrace();
this.setMsg("JSON Error: " + e);
return msg;
}
}
This only happens on the class with a ternary mapping (I can do the same with other classes, all castings are ok).
Any hints / ideas why this casting is generating an error?
JSON Error: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.ngeografics.entities.UsuarioTerritorioPerfil
greetings,
Genis