Ebean 2.6.1 and clobs - 'Bad value for type long'

1,458 views
Skip to first unread message

Alastair

unread,
Jun 7, 2010, 9:27:47 AM6/7/10
to Ebean ORM
Hi,

I've just upgraded from version 2.3.1 to 2.6.1 and I've run into a
problem with clob fields. It seems as if I can write to them, but not
read them - I get a PSQLExcepton when I try.

I'm using Postgres. When I try to read the value of a clob field, I
get this error:


javax.persistence.PersistenceException: Error loading on
com.lurgi.cms.data.TestEntity.description
at
com.avaje.ebeaninternal.server.query.SqlBeanLoad.load(SqlBeanLoad.java:
123)
at
com.avaje.ebeaninternal.server.deploy.BeanProperty.load(BeanProperty.java:
599)
at
com.avaje.ebeaninternal.server.query.SqlTreeNodeBean.load(SqlTreeNodeBean.java:
276)
at com.avaje.ebeaninternal.server.query.CQuery.readRow(CQuery.java:
547)
at
com.avaje.ebeaninternal.server.query.CQuery.readBeanInternal(CQuery.java:
576)
at
com.avaje.ebeaninternal.server.query.CQuery.readTheRows(CQuery.java:
670)
at
com.avaje.ebeaninternal.server.query.CQuery.readCollection(CQuery.java:
655)
at
com.avaje.ebeaninternal.server.query.CQueryEngine.findMany(CQueryEngine.java:
168)
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.loadBean(DefaultBeanLoader.java:
360)
at
com.avaje.ebeaninternal.server.core.DefaultServer.loadBean(DefaultServer.java:
461)
at
com.avaje.ebeaninternal.server.loadcontext.DLoadBeanContext.loadBean(DLoadBeanContext.java:
143)
at
com.avaje.ebean.bean.EntityBeanIntercept.loadBean(EntityBeanIntercept.java:
548)
at
com.avaje.ebean.bean.EntityBeanIntercept.preGetter(EntityBeanIntercept.java:
638)
at
com.lurgi.cms.data.TestEntity._ebean_get_description(TestEntity.java:
4)
at com.lurgi.cms.data.TestEntity.getDescription(TestEntity.java:49)

When I breakpoint at the error, I can see it's thrown a PSQLException
complaining that "org.postgresql.util.PSQLException: Bad value for
type long"

Here's an example entity:

-------------------------------------------------------
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;

@Entity
public class TestEntity
{
@Id
private Long id;

private String name;

@Lob
private String description;


public void setId(Long id) { this.id = id; }
public Long getId() { return id; }

public void setName(String name) { this.name = name; }
public String getName() { return name; }

public void setDescription(String description) { this.description =
description; }
public String getDescription() {return description;}
}
--------------------------------------------

Here's the code I'm calling:

TestEntity entity = new TestEntity();
entity.setName("test");
entity.setDescription("This is a test");
EbeanServer server = Ebean.getServer(datasourceName);
server.save(entity);
server.refresh(entity);
System.out.println("description=" + entity.getDescription());


...and when I try to get the description, there's an internal error:

org.postgresql.util.PSQLException: Bad value for type long : This is a
test

Any ideas what's going on? I used to use two annotations for the
field - @Lob and @Column(columnDefinition="text"). I get the same
problem when I do that.

As I say, this was all fine in 2.3.1 - has something changed in how I
should use this?

Thanks,
Alastair




Rob Bygrave

unread,
Jun 8, 2010, 5:53:19 AM6/8/10
to eb...@googlegroups.com
I have reproduced this on Postgres using the 8.4-701-jdbc4 driver.

Caused by: org.postgresql.util.PSQLException: Bad value for type long : This is a test
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.toLong(AbstractJdbc2ResultSet.java:2796)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.java:2019)
    at org.postgresql.jdbc4.Jdbc4ResultSet.getClob(Jdbc4ResultSet.java:43)
    at com.avaje.ebeaninternal.server.type.RsetDataReader.getStringClob(RsetDataReader.java:190)
    at com.avaje.ebeaninternal.server.type.ScalarTypeClob.read(ScalarTypeClob.java:56)
    at com.avaje.ebeaninternal.server.type.ScalarTypeClob.read(ScalarTypeClob.java:32)
    at com.avaje.ebeaninternal.server.deploy.BeanProperty.read(BeanProperty.java:611)
    at com.avaje.ebeaninternal.server.query.SqlBeanLoad.load(SqlBeanLoad.java:111)
    ... 18 more

According to http://archives.postgresql.org/pgsql-jdbc/2010-02/msg00000.php

... getClob() will not work reading the Postgres text type and we need to use getString() instead. I'm not sure yet why this worked in Ebean v2.3.1.

... but no, there is nothing wrong with your code. As a temporary workaround, if you are not using DDL generation then you can comment out the @Lob annotation for postgres.

Cheers, Rob.

Alastair

unread,
Jun 8, 2010, 9:00:39 AM6/8/10
to Ebean ORM
> According tohttp://archives.postgresql.org/pgsql-jdbc/2010-02/msg00000.php
>
> ... getClob() will not work reading the Postgres text type and we need to
> use getString() instead. I'm not sure yet why this worked in Ebean v2.3.1.

It definitely does - I rolled back to v2.3.1 and it's all ok again.


> ... but no, there is nothing wrong with your code. As a temporary
> workaround, if you are not using DDL generation then you can comment out the
> @Lob annotation for postgres.

Thanks for the suggestion (and for responding so quickly as usual).
At the moment I am using DDL generation as this is a new project and
there's lots of data prototyping going on. I'll stick with v2.3.1 for
now, it's working for everything I need.

Thanks,
Alastair

Alastair

unread,
Jun 8, 2010, 9:28:01 AM6/8/10
to Ebean ORM

>
> It definitely does - I rolled back to v2.3.1 and it's all ok again.

Apologies - I meant v2.3.0, not v2.3.1

Rob Bygrave

unread,
Jun 8, 2010, 4:08:14 PM6/8/10
to eb...@googlegroups.com
I have logged this as http://www.avaje.org/bugdetail-309.html

This is a Postgres specific platform change.
Reply all
Reply to author
Forward
0 new messages