attributes for @Lob annotation

555 views
Skip to first unread message

drewcimino

unread,
Jul 26, 2011, 5:46:23 PM7/26/11
to play-framework
I'm trying to use the @Lob annotation of one of my fields, and specify
that the type in the database should be LONGBLOB. As per the play
docs, I'm using:

@Lob(type=BLOB)
public ArrayList<Element> elements;

But I get a compile error that says:

The file /app/models/Document.java could not be compiled. Error raised
is : The attribute type is undefined for the annotation type Lob


Why is it having issues with me specifying the type?

Thanks,
Drew

Neoh59

unread,
Jul 27, 2011, 3:23:51 PM7/27/11
to play-fr...@googlegroups.com
I don't think you can use @Lob for a List

What you can do :

@ManyToMany
public List<MyEntity> myElements;

And create an other entity :
@Entity
public class MyEntity extends Models {
@Lob(type=BLOB)
public String value;
}

Perhaps myElement is not ManyToMany, or perhaps the association must be defined in MyEntity ... it depends on your app.

PS: I think it's better to declare a List and not an ArrayList, event if you use ArrayList. It's simplier to change to an other List implementation if needed. It's not a Play! advice, but a Java advice.


Rober Magnus

unread,
Jul 27, 2011, 3:37:24 PM7/27/11
to play-fr...@googlegroups.com
On 26.07.2011 23:46, drewcimino wrote:
> I'm trying to use the @Lob annotation of one of my fields, and specify
> that the type in the database should be LONGBLOB. As per the play
> docs, I'm using:
>
> @Lob(type=BLOB)
> public ArrayList<Element> elements;
>
> But I get a compile error that says:
>
> The file /app/models/Document.java could not be compiled. Error raised
> is : The attribute type is undefined for the annotation type Lob

Simple. ;-)

The annotation Lob has no attribute 'type'. You could only use "@Lob".
But I'm not sure what do you wan't. Combining LOB with a list makes no
sense (at last to me ...).


If you use JPA and Hibernate as implementation, this may help

https://hibernate.onjira.com/browse/HHH-4684?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel#issue-tabs

regards,
Robert

--
Robert Magnus
akquinet tech@spree GmbH
Bülowstraße 66, D-10783 Berlin
Tel. +49 (0)30 235 520 - 44 Fax. +49 (0)30 217 520 - 12

Geschäftsführung: Martin Weber, Dr. Torsten Fink
Amtsgericht Berlin-Charlottenburg HRB 86780 B
USt.-Id. Nr.: DE 225 964 680

drewcimino

unread,
Jul 27, 2011, 3:50:27 PM7/27/11
to play-framework
From http://www.playframework.org/documentation/1.2.2/cheatsheet/model

@Lob(fetch=[LAZY, EAGER], type=[BLOB,CLOB])
Defines this field as being stored as a large object

In my database, my field keeps getting automatically set to type
'tinyblob'. Because of this, I keep getting data truncation errors,
and I have to keep changing the field to 'longblob' myself every time
rebuild my database.

I use @Lob elsewhere for a field, which gets set to 'longtext'. If I
use @Lob for something that isn't just simple text, will it realize
that and just change to field to a larger form of the default type,
which is blob?

Regards,
Drew

On Jul 27, 3:37 pm, Rober Magnus <robert.mag...@akquinet.de> wrote:
>
> Simple. ;-)
>
> The annotation Lob has no attribute 'type'. You could only use "@Lob".
> But I'm not sure what do you wan't. Combining LOB with a list makes no
> sense (at last to me ...).
>
> If you use JPA and Hibernate as implementation, this may help
>
> https://hibernate.onjira.com/browse/HHH-4684?page=com.atlassian.jira....

Robert Magnus

unread,
Jul 28, 2011, 3:37:32 AM7/28/11
to play-fr...@googlegroups.com
Hi

Am 27.07.2011 21:50, schrieb drewcimino:
> From
> http://www.playframework.org/documentation/1.2.2/cheatsheet/model
>
> @Lob(fetch=[LAZY, EAGER], type=[BLOB,CLOB]) Defines this field as
> being stored as a large object

I think, this is a bug. As far as I just check, play uses JPA2 with
hibernate as implementation and there is no attribute "type" for the
annotation Lob.

> In my database, my field keeps getting automatically set to type
> 'tinyblob'. Because of this, I keep getting data truncation errors,
> and I have to keep changing the field to 'longblob' myself every
> time rebuild my database.

Have you tried to use the @Column-Annotation? As shown in
http://www.objectdb.com/api/java/jpa/Column you can define a SQL type
there. I've never tried this, but maybe it helps.

Reply all
Reply to author
Forward
0 new messages