将 Oracle 类型映射到 Hibernate 类型
我正在使用 hibernate 工具自动创建一个表示 Oracle 数据库中的表的类,该表有大量列(60 或更多)我已经映射了我认为 hibernate 类型应该是什么,我显然已经当我尝试查询表时得到以下信息时,映射了错误的内容
原因:java.sql.SQLException:无法转换为内部 代表处 oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111) 在 oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145) 在 oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:207) 在 oracle.jdbc.driver.CharCommonAccessor.getLong(CharCommonAccessor.java:238) 在 oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:557) 在 oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1574) 在 org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:61) 在 org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64) 在 org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:254) 在 org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:250) 在 org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:230) 在 org.hibernate.type.AbstractStandardBasicType. Hydro(AbstractStandardBasicType.java:331) 在 org.hibernate.persister.entity.AbstractEntityPersister. Hydro(AbstractEntityPersister.java:2283) 在 org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1527) 在 org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1455) 在 org.hibernate.loader.Loader.getRow(Loader.java:1355) 处 org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:611) 在 org.hibernate.loader.Loader.doQuery(Loader.java:829) 在 org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) 在 org.hibernate.loader.Loader.doList(Loader.java:2542) ... 9 更多
显然,有超过 60 列,很难追踪我错误映射的列,所以我寻找一些关于映射到什么类型的建议。目前,我做出了以下假设
NUMBER(Max length of 12 min length of 2) -> long
VARCHAR2(Max length of 1000 min length of 1) -> string
DATE -> timestamp
编辑:为了澄清上述内容,我有大小范围为 NUMBER(2) - NUMBER(12) 的数字列。 VARCHAR2 列范围为 VARCHAR2(1) - VARCHAR2(1000)
I'm using hibernate tools to automatically create a class that represents a table in an Oracle database, the table has a large number of columns (60 or more) I've mapped what I think the hibernate type should be, I've obviously mapped something wrong as I get the following when trying to query the table
Caused by: java.sql.SQLException: Fail to convert to internal
representation at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:207)
at
oracle.jdbc.driver.CharCommonAccessor.getLong(CharCommonAccessor.java:238)
at
oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:557)
at
oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1574)
at
org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$2.doExtract(BigIntTypeDescriptor.java:61)
at
org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
at
org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:254)
at
org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:250)
at
org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:230)
at
org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:331)
at
org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2283)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1527)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1455)
at org.hibernate.loader.Loader.getRow(Loader.java:1355) at
org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:611) at
org.hibernate.loader.Loader.doQuery(Loader.java:829) at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:2542) ... 9 more
Obviously with there being over 60 columns it's not easy to track down which column(s) I've mapped incorrectly, so I'm looking for a bit of advice of what type to map to. At the moment I've made the following assumptions
NUMBER(Max length of 12 min length of 2) -> long
VARCHAR2(Max length of 1000 min length of 1) -> string
DATE -> timestamp
Edit: To clarify the above I have number columns ranging in size from NUMBER(2) - NUMBER(12). And VARCHAR2 columns ranging from VARCHAR2(1) - VARCHAR2(1000)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,排序它不是映射类型,这是我将列映射到 long 时出现的问题,而它应该是字符串。
Ok sorted it wasn't mapping the types that was the problem I was mapping a column to a long when it should have been a string.