Oracle Blob 字段的 NHibernate 架构导出问题

发布于 2025-01-08 03:57:46 字数 277 浏览 4 评论 0原文

我在使用 NHibernate 的 schemaexport 函数创建 Oracle DB 时遇到问题。 对于定义为 byte[] 的属性,它会创建一个 RAW 类型的 DB 字段(顺便说一句,限制为 2000 字节)。 这个字段类型不足以满足我的需求,我需要 NH 来创建一个 blob 字段。 我怎样才能做到这一点? 我尝试在映射文件(我使用 xml 映射,因此 hbm 文件)中声明字段,指定 type="Binary" 和 type="BinaryBlob",但这些似乎都没有达到预期的效果:创建的字段始终是生的。 有人可以帮我吗?

I'm having an issue creating my Oracle DB with schemaexport function of NHibernate.
For a property defined as byte[], it creates a DB field of type RAW (btw limited to 2000 byte).
This field type is not enough for my needs, and I need NH to create a blob field instead.
How can I achive that?
I tried declaring the field in the mapping file (I use xml mapping, thus hbm files) specifying either type="Binary" and type="BinaryBlob", but none of those seems to have the desired effects: the created field is always a RAW.
Can anyone help me here?

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

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

发布评论

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

评论(3

宁愿没拥抱 2025-01-15 03:57:46
<property name="prop">
  <column name="blobcolumn" sql-type="BinaryBlob">
</property>

更新:也许这也可以解决问题

<property name="prop" type="Binary" length="1000000"/>
<property name="prop">
  <column name="blobcolumn" sql-type="BinaryBlob">
</property>

Update: maybe this could also do the trick

<property name="prop" type="Binary" length="1000000"/>
じ违心 2025-01-15 03:57:46

我有一个类似的问题,解决方案是长度属性:

<property name="Attachment" length="5224880"/>

如果你没有指定长度,那么无论你在类型属性中写入什么,它都会在oracle中以RAW(2000)结尾,因为它的最大值是2000字节,但如果你说我需要5 MB 或以字节为单位,它是 5224880 字节,然后 nhibernate 自动切换到 BLOB,因为它大于 2000 字节,

因此给定 dot net 属性,

 public virtual byte[] Attachment { get; set; }

正确的映射将是

<property name="Attachment" length="5224880"/>

或者您可以探索Nhibernate的codebase(源代码)中的OracleLiteDialect.cs

I had a similar problem and the solution is the length attribute:

<property name="Attachment" length="5224880"/>

If you specify no length then whatever you write in the type attribute it's going to end as RAW(2000) in oracle because its maximum is 2000 bytes, but if you say I need 5 MB or in bytes its 5224880 bytes then nhibernate switch's to BLOB automatically because it's bigger then 2000 bytes

so given the dot net property

 public virtual byte[] Attachment { get; set; }

the proper mapping would be

<property name="Attachment" length="5224880"/>

Or you can explore the OracleLiteDialect.cs in the codebase (source code) of Nhibernate

安穩 2025-01-15 03:57:46

如果有人想要一种约定方式将 byte[] 类型转换为数据库中的 BLOB,我想出了这个:

public class ByteArrayToDbBlobConvention : IPropertyConvention, IPropertyConventionAcceptance
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Type == typeof(byte[]));            
    }

    public void Apply(IPropertyInstance instance)
    {
        instance.CustomSqlType("BLOB");
    }
}

If someone wants a convention way to do the byte[] type translate into BLOB in database i came up with this:

public class ByteArrayToDbBlobConvention : IPropertyConvention, IPropertyConventionAcceptance
{
    public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
    {
        criteria.Expect(x => x.Type == typeof(byte[]));            
    }

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