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:

@Entity
@Table(name="editore")
public class Editore implements Cloneable, Serializable {

private static final long serialVersionUID = 1L;

@Id
private Integer id;
private String descrizione;

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

public Integer getId() { return id; }
public void setId(Integer id) { this.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:

Ebean.getServer(null);
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.id, 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 e.id 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.id, 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
## -------------------------------------------------------------
x-logging.properties.file=logging.properties


## -------------------------------------------------------------
## 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.

#load.properties.override=${CATALINA_HOME}/conf/myapp.ebean.properties


#ebean.autofetch.querytuning=true
#ebean.autofetch.profiling=true
#ebean.autofetch.implicitmode=default_on
#ebean.autofetch.profiling.min=1
#ebean.autofetch.profiling.base=10
#ebean.autofetch.profiling.rate=0.05


## -------------------------------------------------------------
## Transaction Logging
## -------------------------------------------------------------
ebean.debug.sql=true
ebean.debug.lazyload=true

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


## location of transaction logs
ebean.log.directory=logs
#ebean.log.directory=${catalina.base}/logs/trans

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

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

## Specific Log levels
## 0=none 1=summary 2=bindings 3=sql
ebean.log.iud=3
ebean.log.findid=3
ebean.log.findmany=3

##ebean.transaction.rollbackOnChecked=false

ebean.type.boolean.false=F
ebean.type.boolean.true=T
## use varchar or integer (defaults to varchar)
#ebean.type.boolean.dbtype=varchar

## Default (Ebean DataSourceFactory)
ebean.datasource.factory=default

datasource.default=postgres

datasource.postgres.username=xxx
datasource.postgres.password=xxx
datasource.postgres.databaseUrl=jdbc:postgresql://127.0.0.1:5432/public
datasource.postgres.databaseDriver=org.postgresql.Driver
datasource.postgres.minConnections=1
datasource.postgres.maxConnections=25
datasource.postgres.isolationlevel=read_committed
datasource.postgres.heartbeatsql=select count(*) from editore


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


ebean.updatetimestamp.property=updtime
ebean.updatetimestamp.dbcolumn=updtime

ebean.inserttimestamp.property=cretime
ebean.inserttimestamp.dbcolumn=cretime

ebean.counter.property=vercount
ebean.counter.dbcolumn=vercount


Regards

Claudio

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

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