I have a simple EntityBean with a @Lob
annotation. If I delete this annotation I get no errors on JBossAS 6.0.0.Final and MySQL5. But if I annotate it with @Lob
(because mt
contains about 100 to 5000 characters in my case) I get errors in my testing environment if I persist the entity.
- without
@Lob
:mt
is mapped to VARCHAR - with
@Lob
:mt
is mapped to LONGTEXT (this is what I want, but I get errors)
This my entity:
@Entity
@Table(name = "Description")
public class Description implements Serializable
{
public static final long serialVersionUID=1;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
@Lob
private String mt;
} // ... getter/setter
The error are here:
...
Caused by: org.hibernate.exception.GenericJDBCException: could not insert
[my.Description]
...
Caused by: java.sql.SQLException: Connection is not associated with a managed
connection.org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6@3e4dd
...
I really don't know why I get this (reproduceable) error. The environment seems to be ok, many other tests are passed and it even works without the @Lob
annotation.
This question is related to JPA: how do I persist a String into a database field, type MYSQL Text, where the usage of @Lob
for JPA/MySQL is the accepted answer.
Update 1 The error above is OS specific. On a W7 machine I have no problems with @Lob
, with OSX Lion always the error. I will try to update MySQL and the driver.
Update 2 The proposed workaround by Kimi with @Column(columnDefinition = "longtext")
works fine, even on OSX. In both cases MySQL creates the same column: LONGTEXT.
Update 3 I updated MySQL to mysql-5.5.17-osx10.6-x86_64
and the connector to mysql-connector-java-5.1.18
. Still the same error.