Please use the google group to ask questions - thanks.

by Claudio 27 Dec 11:16
Problems with Postgresql and autofetch?

Hi rob,

I'm trying to fetch a list of objects of type Editore from Postgresql:

public class Editore implements Cloneable, Serializable {

private static final long serialVersionUID = 1L;

private Integer id;
private String descrizione;

public String toString() { return "Editore con descrizione \"" + descrizione + "\""; }

public Integer getId() { return id; }
public void setId(Integer id) { = id; }
public String getDescrizione() { return descrizione; }
public void setDescrizione(String descrizione) { this.descrizione = descrizione; }

The class is enhanced using the Eclipse plugin.
The code to load the list is:

List list = Ebean.find(Editore.class).findList();
for (Editore editore : list) System.out.println(editore.toString());

The first time i run the test i have the Editore objects correctly populated (in log I find ... select, e.descrizione from editore e ...).
If i run the test again only the id field has a value, the descrizione field is null (in log I find ... select from editore e ...).

Adding a @Column annotation to descrizione does not affect the result.
Deleting the ebean.postgres.dictionary file does not affect the result.
If I add a @Id annotation to descrizione the values is loaded.
If I delete the ebean.postgres.autofetch file the test works, but then the file is recreated and I have problems the next time.
Commenting out in the property file ebean.autofetch.querytuning=true solve the problem.
So it's like the columns values are not loaded when ebean.autofetch.querytuning = true

I'm doing something wrong or is a bug?

The log is:

27-dic-2008 12.06.43 com.avaje.ebean.Ebean$ServerManager createServerFactory
INFO: Ebean Version[1.0.1-081216] Java Version[1.6.0_03]
27-dic-2008 12.06.43 com.avaje.ebean.server.core.BootupClassPathSearch search
INFO: Classpath search hits in jars[ebean-1.0.1.jar] pkgs[it.fc.cesena.comune.catalogo.model.db, com.avaje.ebean.meta, com.avaje.ebean.server.bean] searchTime[32]
27-dic-2008 12.06.43 com.avaje.ebean.server.lib.sql.DataSourcePool initialise
INFO: DataSourcePool [postgres] autoCommit[false] transIsolation[READ_COMMITTED] min[1] max[25]
27-dic-2008 12.06.43 com.avaje.ebean.server.lib.sql.DataSourcePool createConnection
INFO: DataSourcePool [postgres] grow pool; busy[0] size[0] max[25]
27-dic-2008 12.06.43 com.avaje.ebean.server.plugin.PluginDbConfig deserializeDictionary
INFO: DictionaryInfo deserialized from file [C:\Documents and Settings\claudio\Documenti\lavoro\workspace\catalogo\.\.ebean.postgres.dictionary]
27-dic-2008 12.06.43 com.avaje.ebean.server.deploy.BeanDescriptorFactory
INFO: Validation: [on] autocreate.notnull=[true] autocreate.length=[true max 4000]
27-dic-2008 12.06.43 com.avaje.ebean.server.deploy.DeploymentManager findAllOrmXml
INFO: No deployment xml (orm.xml etc) was loaded.
27-dic-2008 12.06.43 com.avaje.ebean.server.deploy.BeanDescriptorFactory logStatus
INFO: Entities enhanced[1] subclassed[0]
27-dic-2008 12.06.43 com.avaje.ebean.server.transaction.TransactionLogManager
INFO: Transaction logs in: logs
27-dic-2008 12.06.43 com.avaje.ebean.server.plugin.PluginDbConfig deserializeAutoFetch
INFO: AutoFetch deserialized from file [C:\Documents and Settings\claudio\Documenti\lavoro\workspace\catalogo\.\.ebean.postgres.autofetch]
27-dic-2008 12.06.43 com.avaje.ebean.server.autofetch.DefaultAutoFetchManagerLogging logToJavaLogger
INFO: AutoFetch queryTuning[false] profiling[false] implicitMode[DEFAULT_ON_IF_EMPTY] profiling rate[0.05] min[1] base[10]
27-dic-2008 12.06.43 com.avaje.ebean.server.core.DefaultServerFactory createServer
INFO: Plugin[postgres][com.avaje.ebean.server.plugin.PluginDbConfig]

select, e.descrizione
from editore e

27-dic-2008 12.06.43 com.avaje.ebean.server.transaction.TransactionManager notifyOfQueryOnly
INFO: Transaction [1001] Rollback queryOnly

My properties file is:

## -------------------------------------------------------------
## Reload java.util.logging properties file
## -------------------------------------------------------------

## -------------------------------------------------------------
## Load (Dev/Test/Prod) server specific properties
## -------------------------------------------------------------
## This is a possible alternative to using JNDI to set environment
## properties externally (to the WAR file). This is another way
## your Dev, Test and Prod servers can have different properties.${CATALINA_HOME}/conf/


## -------------------------------------------------------------
## Transaction Logging
## -------------------------------------------------------------

## Log transaction begins and ends etc
## (0=NoLogging 1=minimal ... 9=logAll)

## location of transaction logs${catalina.base}/logs/trans

## General logging level: (0=None, 1=Explicit, 2=All)

## Sharing log files: (0=None Share, 1=Implicit Share, 2=All Share)

## Specific Log levels
## 0=none 1=summary 2=bindings 3=sql


## use varchar or integer (defaults to varchar)

## Default (Ebean DataSourceFactory)


datasource.postgres.heartbeatsql=select count(*) from editore

## -------------------------------------------------------------
## Naming Conventions
## -------------------------------------------------------------



03 Jan 10:10
by Rob

This looks like the correct behaviour of autofetch.

The thing to note is that with Ebean the toString() method is *NOT* intercepted. So if you change your program to use the getDescrizione() rather than toString() then you will see a difference.

Using.... System.out.println(editore.getDescrizione());
rather than... System.out.println(editore.toString());

With getDescrizione() autofetch will tune the query based the application using the "descrizione property" ... but with the application code as it is using toString() autofetch is tuning as if you didn't use descrizione which is why the query does not include descrizione in the query.

The reason toString() is treated as a special case (in terms of interception) is because toString() is used by IDE's when running in debug mode. This means that when you inspect entities in an IDE using a debugger you should not get lazy loading to fire.

So, as I see it is the special treatment of toString() which is confusing here. Hopefully that makes sense.

Cheers, Rob.

Create a New Topic

Introduction User Guide (pdf) Install/Configure Public JavaDoc Whitepapers
General Database Specific Byte Code Deployment Annotations Features
Top Bugs Top Enhancements