如何配置Doctrine实体来处理数据库中的压缩blob?

时间:2012-03-08 10:54:15

标签: doctrine doctrine-orm entity blob

我使用Doctrine 2作为数据库的ORM,我遇到了压缩blob的问题。

我将文本存储在数据库中的压缩blob列中。我如何在实体映射xml配置中指定它?我目前正在为此列使用type="blob",但这不会返回字符串。我可以使用type="text"但这会返回垃圾,因为它没有解压缩它。

我可以在实体配置中指定此文本在检索时需要解压缩并在持久化时压缩吗?

这是我的实体配置:

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
    http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="AccountNote" table="tblAccountNote">
        <id name="intAccountNoteId" type="integer">
            <generator strategy="AUTO" />
        </id>
        <field name="intAccountId" type="integer" nullable="false" unique="no" />
        <field name="bolHiddenNote" type="boolean" nullable="false" unique="no" />
        <field name="binNote" type="blob" nullable="false" unique="no" />
        <field name="strHash" type="string" length="32" nullable="true" unique="no" />
        <field name="dtmCreated"   type="datetime" nullable="false" unique="no" />
        <field name="stmTimestamp" type="datetime" nullable="false" unique="no" />
        <many-to-one field="objAccount" target-entity="Account" inversed-by="objNotes">
            <join-column name="intAccountId" referenced-column-name="intAccountId" />
        </many-to-one>
    </entity>

</doctrine-mapping>

1 个答案:

答案 0 :(得分:3)

最后,我们决定在getter和setter中处理压缩并将其从模式中删除。