Hibernate + PostgreSQL +网络地址类型(inet,cdir)

编程入门 行业动态 更新时间:2024-10-26 00:19:03
本文介绍了Hibernate + PostgreSQL +网络地址类型(inet,cdir)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经用Hibernate 4.2.7和PostgreSQL 9.3.1开始了我的示例项目,并且一切都很顺利。

目前我想使用 INET PostgreSQL类型,但我无法将其与Hibernate进行映射。

我得到了这个hibernate错误:无法确定类型:inet,表中:DEVICE_IP_ADDRESS,列...

我使用

我的hibernate映射文件:

< property name =ipAddresstype =inet> < column name =IP_ADDRESSnot-null =true/> < / property>

我问过谷歌,但我找不到任何可用的解决方案。 你可以帮我吗? $ th $!

编辑:你是什么如果我想使用'extra'postgresql类型和 PostGIS 类型,请考虑需要使用哪种ORM实现?

或者我需要使用简单的JDBC?

最近与Hibernate 3& Postgres 9.由于hibernate没有为postgres中的String String []提供字符串数组的内置映射,我最终实现了一个自定义的映射类。您可以尝试以下步骤。

  • 创建实现org.hibernate.usertype.UserType的自定义类PgInet(此UserType类是根据我的hibernate 3的知识。不知道这是否已经在Hibernate 4中改变了。)
  • 下面的方法实现将是关键。

    • 等于
    • nullSafeGet
    • nullSafeSet
    • returnedClass 返回InetAddress.class;
    • sqlTypes 返回新的int [] {java.sql.Types。}
  • 完成上述操作后,我们只需将HBM.xml中的属性类型设置为该类即PgInet。 b $ b

    对于定制类实现,请尝试引用现有类型实现类。你应该能够找到类文件。使用下面的链接作为参考。

    grepcode/file/repo1.maven/maven2/hibernate/hibernate/2.1.8/net/sf/ hibernate / type / ArrayType.java

    希望这有助于您。

    谢谢。

    >

    I have started my example project with Hibernate 4.2.7 and PostgreSQL 9.3.1 and everything is going well.

    At the moment I would like to use INET PostgreSQL type but I am not able to map it with Hibernate.

    I got this hibernate error: Could not determine type for: inet, at table: DEVICE_IP_ADDRESS, for columns...

    I use org.hibernate.dialect.PostgreSQLDialect and hbm.xml configuratiin files.

    My hibernate mapping file:

    <property name="ipAddress" type="inet"> <column name="IP_ADDRESS" not-null="true" /> </property>

    I asked the google but I could not find any usable solution. Could you help me?

    Thx!

    EDIT: What do you think what kind of ORM implementation do I need to use if I want to use the 'extra' postgresql types and PostGIS types?

    Or I need to use the simple JDBC?

    解决方案

    I faced similar problem recently with Hibernate 3 & Postgres 9. Since there was no inbuilt mapping provided for String Array in postgres to Java String[] by hibernate, I end up implementing a custom mapping class. You can try following below steps.

  • Create Custom class "PgInet" which implements "org.hibernate.usertype.UserType" (this UserType class is per my hibernate 3 knowledge. Not sure if this has been changed in Hibernate 4).
  • Below method implementation would be critical.

    • equals
    • nullSafeGet
    • nullSafeSet
    • returnedClass return InetAddress.class;
    • sqlTypes return new int[] {java.sql.Types.}
  • Once above is done, we just need to set type of property in HBM.xml to this class i.e. PgInet.

    For custom class implementation try referring to existing type implementation class. You should be able to locate class files. Use below link as reference.

    grepcode/file/repo1.maven/maven2/hibernate/hibernate/2.1.8/net/sf/hibernate/type/ArrayType.java

    Hope this helps.

    Thanks.

    更多推荐

    Hibernate + PostgreSQL +网络地址类型(inet,cdir)

    本文发布于:2023-10-19 14:36:31,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:网络地址   类型   PostgreSQL   Hibernate   inet

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!