I have a simple EntityBean with @Lob
annotation. If I delete this annotation, I will not get errors on JBossAS 6.0.0.Final and MySQL5. But if I annotate it using @Lob
(because mt
contains in my case about 100-500 characters), I get errors in my test environment if I save the object.
- without
@Lob
: mt
displayed in VARCHAR - with
@Lob
: mt
displayed in LONGTEXT (this is what I want but get errors)
This is my essence:
@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; }
The error is here:
... Caused by: org.hibernate.exception.GenericJDBCException: could not insert [my.Description] ... Caused by: java.sql.SQLException: Connection is not associated with a managed connec tion.org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6@ 3e4dd ...
I really don't know why I am getting this (reproducible) error. The environment seems to be in order, many other tests passed and even work without the @Lob
annotation.
This question is related to JPA: how to @Lob
string in a database field, enter MYSQL text , where using @Lob
for JPA / MySQL is the accepted answer.
Update 1 The above error is OS-specific. On a W7 machine, I have no problem with @Lob
, while OSX Lion is always a bug. I will try to update MySQL and the driver.
Update 2 Kimi's proposed solution with @Column(columnDefinition = "longtext")
works fine even on OSX. In both cases, MySQL creates the same column: LONGTEXT.
Update 3 . I upgraded MySQL to mysql-5.5.17-osx10.6-x86_64
and connector to mysql-connector-java-5.1.18
. All the same mistakes.
source share