JBoss6 JPA:带有 @Lob 的实体导致 GenericJDBCException
我有一个带有 @Lob
注释的简单 EntityBean。如果我删除这个注释,我在 JBossAS 6.0.0.Final 和 MySQL5 上不会出现错误。但是,如果我用 @Lob 对其进行注释(因为在我的情况下,mt 包含大约 100 到 5000 个字符),如果我保留该实体,我会在测试环境中收到错误。
- 没有
@Lob
:mt
映射到 VARCHAR - 使用
@Lob
:mt
映射到 LONGTEXT (这就是我想要,但我收到错误)
这是我的实体:
@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
错误在这里:
...
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
...
我真的不知道为什么我收到这个(可重现的)错误。环境似乎没问题,许多其他测试都通过了,甚至在没有 @Lob
注解的情况下也能工作。
这个问题与 JPA: how do I persist a String into a database field, type MYSQL Text 相关,其中使用 @Lob
for JPA/MySQL 是可接受的答案。
更新 1 上述错误是操作系统特定的。在 W7 机器上,我对 @Lob
没有任何问题,而 OSX Lion 总是出现错误。我会尝试更新MySQL和驱动程序。
更新 2 Kimi 使用 @Column(columnDefinition = "longtext")
提出的解决方法即使在 OSX 上也能正常工作。在这两种情况下,MySQL 创建相同的列:LONGTEXT。
更新 3 我将 MySQL 更新为 mysql-5.5.17-osx10.6-x86_64
并将连接器更新为 mysql-connector-java-5.1.18
>。还是同样的错误。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有需要使用
@Lob
注释字符串属性。只需使用@Column(length = 10000)
设置列长度。编辑:
此外,您始终可以将长度设置为数据库特定的最大值,并使用
columndefinition
设置来定义列类型,以适合您的需要。例如,如果您使用 MySQL 5.0.3 或更高版本,则每种数据类型可以存储的最大数据量如下:
据我了解,@Lob 只是根据底层数据库设置列类型和长度。
There is no need to annotate a String property with
@Lob
. Just set the column length with@Column(length = 10000)
.EDIT:
Moreover, you can always set the length to your database specific maximum value, as well as define the column type with the
columndefinition
setting to whichever suits your needs.For example, if you're using MySQL 5.0.3 or later, the maximum amount of data that can be stored in each data type is as follows:
As i understand it,
@Lob
just sets the column type and length depending on the underlying database.对我有用的另一种方法是更新 jBoss 的启动配置,
我正在运行 jBoss6 和 MySQL5
Another way that worked for me is to update launch configuration of jBoss with
I'm running jBoss6 with MySQL5