如何在 hibernate 中将我的 blob 列从 mysql 读取为字符串类型

发布于 2024-07-26 04:37:51 字数 687 浏览 3 评论 0原文

如何在 hibernate 中将我的 blob 列从 mysql 读取为字符串类型

我已经尝试过这种方法,但总是返回我: [B@196f4b5

        Article article2=f.daoArticle.findById(article.getSrcUrl());

        String vbody = article2.getArticle();
           System.out.println(vbody);
\\hbm
 <class catalog="ariso" name="countaword.ariso.dao.Article" table="article">
  <id name="srcUrl" type="java.lang.String">
   <column length="200" name="SrcUrl"/>
   <generator class="assigned"/>
  </id>
  <property column="Article" generated="never" lazy="false"
   name="article" type="text" not-null="true" length="10485760"/>
 </class>

\\

有帮助吗? 我花了3个小时!!!

how to read my blob column from mysql to string type in hibernate

I have try this way but alway return me:
[B@196f4b5

        Article article2=f.daoArticle.findById(article.getSrcUrl());

        String vbody = article2.getArticle();
           System.out.println(vbody);
\\hbm
 <class catalog="ariso" name="countaword.ariso.dao.Article" table="article">
  <id name="srcUrl" type="java.lang.String">
   <column length="200" name="SrcUrl"/>
   <generator class="assigned"/>
  </id>
  <property column="Article" generated="never" lazy="false"
   name="article" type="text" not-null="true" length="10485760"/>
 </class>

\\

any helps? It took me 3 hours!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

偏爱自由 2024-08-02 04:37:51

我建议您从 interwebtubes 检查以下页面:

https://www.hibernate.org/76.html

它描述了如何创建自定义 Hibernate UserType 以将 CLOB/BLOB 映射到字符串。

I suggest you check the following page from the interwebtubes:

https://www.hibernate.org/76.html

It describes how to create a custom hibernate UserType to map a CLOB/BLOB to a string.

随心而道 2024-08-02 04:37:51

您可以使用这个来自 spring-orm 库的类。 但请注意,Springs (B|C)LOB 处理依赖于许多需要正确初始化的框架类。 我认为你应该切换到使用 spring 来完全处理 hibernate,或者只是使用类的源代码作为灵感。

You could use this class from the spring-orm library. Be aware, though, that Springs (B|C)LOB handling relies on a lot of framework classes that need to be initialized correctly. I think you should either switch to using spring for handling hibernate completely or just use the class' source as inspiration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文