Hibernate + PostgreSQL +网络地址类型(inet,cdir) [英] Hibernate + PostgreSQL + Network Address Type (inet, cdir)

查看:182
本文介绍了Hibernate + PostgreSQL +网络地址类型(inet,cdir)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



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



我使用和hbm.xml配置文件。

我的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 []提供字符串数组的内置映射,我最终实现了一个自定义的映射类。您可以尝试以下步骤。


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

  2. 下面的方法实现将是关键。




    • 等于
    • nullSafeGet

    • nullSafeSet
    • returnedClass
      返回InetAddress.class;

    • sqlTypes
      返回新的int [] {java.sql.Types。}


完成上述操作后,我们只需将HBM.xml中的属性类型设置为该类即PgInet。 b
$ b

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



http://grepcode.com/file/repo1.maven.org/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.

  1. 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).
  2. 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.

http://grepcode.com/file/repo1.maven.org/maven2/hibernate/hibernate/2.1.8/net/sf/hibernate/type/ArrayType.java

Hope this helps.

Thanks.

这篇关于Hibernate + PostgreSQL +网络地址类型(inet,cdir)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆