Error fetching bean

125 views
Skip to first unread message

claudio

unread,
Aug 1, 2010, 6:03:55 PM8/1/10
to Ebean ORM
Hi, I have a problem fetching a bean containing other beans; here is
some code:

@Entity
public class Abitazione implements Serializable {
@Id private Integer id;
@OneToMany(cascade=CascadeType.ALL, mappedBy="abitazione")
@PrivateOwned List<Pratica> pratiche;
@Version int updateCount;
...
}

@Entity
public class Pratica implements Serializable {
@Id private Integer id;
@ManyToOne(optional=false) private Abitazione abitazione;
@OneToOne(cascade=CascadeType.ALL, optional=true, mappedBy="pratica")
@PrivateOwned private ConformitaEdilizia conformita;
@OneToOne(cascade=CascadeType.ALL, optional=true, mappedBy="pratica")
@PrivateOwned private ParereIgienicoSanitario parere;
@Version private int updateCount;
...
}

@Entity
public class ParereIgienicoSanitario implements Serializable {
@Id private Integer id;
@OneToOne(optional=false) private Pratica pratica;
@Version private int updateCount;
...
}

@Entity
public class ConformitaEdilizia implements Serializable {
@Id private Integer id;
@OneToOne(optional=false) private Pratica pratica;
@Version private int updateCount;
...
}

So a bean of class Abitazione has a list of beans of class Pratica.
Pratica has one ParereIgienicoSanitario and one ConformitaEdilizia.

If I try to load a bean of class Abitazione ad read the list of
Pratica:

abitazione = Ebean.find(idoneitaalloggiativa.model.Abitazione.class,
100);

for (idoneitaalloggiativa.model.Pratica pratica :
abitazione.getPratiche()) {
System.out.println(pratica);
System.out.println(pratica.getConformita());
System.out.println(pratica.getParere());
}

I get an error:

Exception in thread "main" javax.persistence.PersistenceException:
Query threw SQLException:Column "AA.ID" not found; SQL statement:
select a.id c0
, ap.id c1, ap.update_count c2, ap.abitazione_id c3, apc.id
c4, aa.id c5
from ABITAZIONE a
left outer join PRATICA ap on ap.abitazione_id = a.id
left outer join CONFORMITA apc on apc.pratica_id = ap.id
left outer join PARERE app on app.pratica_id = ap.id
where a.id = ?
order by a.id [42122-140] Query was:
select a.id c0
, ap.id c1, ap.update_count c2, ap.abitazione_id c3, apc.id
c4, aa.id c5
from ABITAZIONE a
left outer join PRATICA ap on ap.abitazione_id = a.id
left outer join CONFORMITA apc on apc.pratica_id = ap.id
left outer join PARERE app on app.pratica_id = ap.id
where a.id = ?
order by a.id


at
com.avaje.ebeaninternal.server.query.CQueryEngine.findMany(CQueryEngine.java:
204)
at
com.avaje.ebeaninternal.server.query.DefaultOrmQueryEngine.findMany(DefaultOrmQueryEngine.java:
89)
at
com.avaje.ebeaninternal.server.core.OrmQueryRequest.findList(OrmQueryRequest.java:
298)
at
com.avaje.ebeaninternal.server.core.DefaultServer.findList(DefaultServer.java:
1369)
at
com.avaje.ebeaninternal.server.core.DefaultBeanLoader.loadMany(DefaultBeanLoader.java:
162)
at
com.avaje.ebeaninternal.server.core.DefaultServer.loadMany(DefaultServer.java:
446)
at
com.avaje.ebeaninternal.server.loadcontext.DLoadManyContext.loadMany(DLoadManyContext.java:
142)
at
com.avaje.ebean.common.AbstractBeanCollection.lazyLoadCollection(AbstractBeanCollection.java:
152)
at com.avaje.ebean.common.BeanList.init(BeanList.java:116)
at com.avaje.ebean.common.BeanList.iterator(BeanList.java:288)
at idoneitaalloggiativa.testerror.TestError.main(TestError.java:38)
Caused by: org.h2.jdbc.JdbcSQLException: Column "AA.ID" not found; SQL
statement:
select a.id c0
, ap.id c1, ap.update_count c2, ap.abitazione_id c3, apc.id
c4, aa.id c5
from ABITAZIONE a
left outer join PRATICA ap on ap.abitazione_id = a.id
left outer join CONFORMITA apc on apc.pratica_id = ap.id
left outer join PARERE app on app.pratica_id = ap.id
where a.id = ?
order by a.id [42122-140]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:
327)
at org.h2.message.DbException.get(DbException.java:167)
at org.h2.message.DbException.get(DbException.java:144)
at org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:
127)
at org.h2.expression.Alias.optimize(Alias.java:47)
at org.h2.command.dml.Select.prepare(Select.java:738)
at org.h2.command.Parser.prepare(Parser.java:202)
at org.h2.command.Parser.prepareCommand(Parser.java:214)
at org.h2.engine.Session.prepareLocal(Session.java:434)
at org.h2.engine.Session.prepareCommand(Session.java:384)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:
1071)
at
org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:
71)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:
234)
at
com.avaje.ebeaninternal.server.lib.sql.PooledConnection.prepareStatement(PooledConnection.java:
426)
at
com.avaje.ebeaninternal.server.lib.sql.PooledConnection.prepareStatement(PooledConnection.java:
396)
at
com.avaje.ebeaninternal.server.query.CQuery.prepareBindExecuteQuery(CQuery.java:
396)
at
com.avaje.ebeaninternal.server.query.CQueryEngine.findMany(CQueryEngine.java:
162)
... 10 more


Ebean log is:

1-ago-2010 23.52.09 com.avaje.ebean.config.PropertyMapLoader load
GRAVE: ebean.properties not found
1-ago-2010 23.52.09
com.avaje.ebeaninternal.server.lib.sql.DataSourcePool initialise
INFO: DataSourcePool [certificazioni] autoCommit[false]
transIsolation[READ_COMMITTED] min[2] max[20]
1-ago-2010 23.52.10
com.avaje.ebeaninternal.server.core.DefaultServerFactory
setDatabasePlatform
INFO: DatabasePlatform name:certificazioni platform:h2
1-ago-2010 23.52.10
com.avaje.ebeaninternal.server.subclass.SubClassManager$1 run
INFO: SubClassFactory parent ClassLoader [sun.misc.Launcher
$AppClassLoader]
1-ago-2010 23.52.10
com.avaje.ebeaninternal.server.type.DefaultTypeManager
initialiseJodaTypes
INFO: Registering Joda data types
1-ago-2010 23.52.10
com.avaje.ebeaninternal.server.resource.ResourceManagerFactory
createFileSource
INFO: ResourceManager initialised: type[file] [C:\Documents and
Settings\claudio\Documenti\lavoro\workspace\idoneitaalloggiativa_old
\WebContent\WEB-INF]
1-ago-2010 23.52.10 com.avaje.ebeaninternal.server.deploy.DeployOrmXml
findAllOrmXml
INFO: No deployment xml (orm.xml etc) was loaded.
1-ago-2010 23.52.10
com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager logStatus
INFO: Entities enhanced[4] subclassed[0]
1-ago-2010 23.52.10
com.avaje.ebeaninternal.server.transaction.TransactionLogManager
<init>
INFO: Transaction logs in: logs
1-ago-2010 23.52.10
com.avaje.ebeaninternal.server.autofetch.AutoFetchManagerFactory
deserializeAutoFetch
INFO: AutoFetch deserialized from file [C:\Documents and Settings
\claudio\Documenti\lavoro\workspace\idoneitaalloggiativa_old\WebContent
\WEB-INF\.ebean.certificazioni.autofetch]
1-ago-2010 23.52.10
com.avaje.ebeaninternal.server.autofetch.DefaultAutoFetchManagerLogging
logToJavaLogger
INFO: AutoFetch queryTuning[true] profiling[true]
mode[DEFAULT_ONIFEMPTY] profiling rate[0.05] min[1] base[10]
1-ago-2010 23.52.10 com.avaje.ebean.Ebean <clinit>
INFO: Ebean Version[2.6.1] Java Version[1.6.0_18]


If I leave only one OneToOne association in Pratica all works
properly.
Seems like an error generating the column alias of the OneToOne
properties of Pratica. Or perhaps my mapping is not correct.

Can You help?

Thanks

Claudio

Rob Bygrave

unread,
Aug 10, 2010, 4:31:42 AM8/10/10
to eb...@googlegroups.com

Can you create a test case and upload it (to the google group) ?

Thanks, Rob.

claudio

unread,
Aug 22, 2010, 11:12:29 AM8/22/10
to Ebean ORM
Test Case uploaded (ebeantest.zip).
It is a compressed Eclipse project: you need to change the path to the
db and run TestError.java.

I noted that:
1. if I add the Pratica Object to an Abitazione object and save the
latter, all works.
2. if I create an Abitazione object, save it, Create a Pratica object,
set the abitazione and save it, when i reload the abitazione and try
to get the list of Pratica I get the error.

Thanks

Claudio

Rob Bygrave

unread,
Sep 17, 2010, 5:34:36 AM9/17/10
to eb...@googlegroups.com
Hi Claudio,

Apologies ... I am trying to download the ebeantest.zip and I am getting some odd error (the page does not exist).

Can you upload the test case again?


Thanks, Rob.

claudio

unread,
Sep 17, 2010, 7:54:10 PM9/17/10
to Ebean ORM
Hi Rob,
seems there is a problem uploading zip files, so I changed the
extension.
Now it works, just save the file (ebeantest.zip.new) and delete
the .new.
N.B. I omitted the jars in the lib folder so to run the project you
need a H2 ver. 1.2 jar in addition to Ebean jars.

many thanks

Claudio

Rob Bygrave

unread,
Sep 17, 2010, 9:15:13 PM9/17/10
to eb...@googlegroups.com
Great. I have downloaded it and reproduced the error.

Thanks.

Rob Bygrave

unread,
Sep 18, 2010, 5:57:33 AM9/18/10
to eb...@googlegroups.com
FYI:

Definately a bug.  Logged as BUG 321 : Incorrect table alias with Multiple OneToOne on bean

Fixed in HEAD. Thanks for the test case.

Cheers, Rob.
Reply all
Reply to author
Forward
0 new messages