我已经用Hibernate 4.2.7和PostgreSQL 9.3.1开始了我的示例项目,并且一切都很顺利。
目前我想使用 INET PostgreSQL类型,但我无法将其与Hibernate进行映射。
我得到了这个hibernate错误:无法确定类型:inet,表中:DEVICE_IP_ADDRESS,列...
我使用 我的hibernate映射文件: 我问过谷歌,但我找不到任何可用的解决方案。 你可以帮我吗? $ th $! 编辑:你是什么如果我想使用'extra'postgresql类型和 PostGIS 类型,请考虑需要使用哪种ORM实现? 或者我需要使用简单的JDBC?
下面的方法实现将是关键。
- 等于
- 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.
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)
发布评论