null pointer exception in complex object

Skip to first unread message

Mar 13, 2017, 6:50:03 PM3/13/17
to sql2o

Hi, I have this classes:

public class Pais implements Serializable {
   public void setIdpais(Integer idpais) {
        this.idpais = idpais;
    public Integer getIdpais() {
        return idpais;
public class Usuario implements Serializable {
   private Integer idusuario;
   private Pais pais;
   public Integer getIdusuario() {
       return idusuario;

  public void setIdusuario(Integer idusuario) {
       this.idusuario = idusuario;

   public Pais getPais() {
       return pais;

   public void setPais(Pais pais) {
       this.pais = pais;

running this query:

con.createPreparedQuery(" SELECT *    FROM usuario      where idusuario = :id")
                .addParameter("id", 1)
                .addColumnMapping("idpais", "pais.idpais")

i get this error:

ERROR [http-nio-8084-exec-223] ( - 
org.sql2o.Sql2oException: Could not map idpais to any property.
	at org.sql2o.DefaultResultSetHandlerFactory.newResultSetHandler0(
	at org.sql2o.DefaultResultSetHandlerFactory.access$200(
	at org.sql2o.DefaultResultSetHandlerFactory$5.evaluate(
	at org.sql2o.DefaultResultSetHandlerFactory$5.evaluate(
	at org.sql2o.DefaultResultSetHandlerFactory.newResultSetHandler(
	at org.sql2o.PojoResultSetIterator.<init>(
	at org.sql2o.Query$14.iterator(
	at org.sql2o.Query.executeAndFetch(
	at org.sql2o.Query.executeAndFetch(

what is the correct way to do this?

Николай Митропольский

Mar 14, 2017, 4:37:37 AM3/14/17
to sql2o,

I think it is not possible to do this directly. Because sql2o is not an ORM and could not handle such complex things. But you cold try to add a converter class 

for Pais
to make it possible to create Pais instance from integers. 

вторник, 14 марта 2017 г., 1:50:03 UTC+3 пользователь написал:

Mar 14, 2017, 12:02:51 PM3/14/17
to sql2o,

After read this:

i achieve this changing the query:

    SELECT nombre, idpais as "pais.idpais"
    FROM usuario     
    where idusuario = ?

and deleting the addcolumnMapping. in the post speak about the need of the public atributes, but that is not necessary in 1.6.rc3. Maybe is a problem with my concept of the columnMapping

Николай Митропольский

Mar 15, 2017, 1:12:57 AM3/15/17
to sql2o,
hm, thats funny. I didn't know about it. About a column mapping it seems that splitting paths by dots is done before column mapping:

вторник, 14 марта 2017 г., 19:02:51 UTC+3 пользователь написал:
Reply all
Reply to author
0 new messages