休眠。 PSQLException:int类型的错误值:admin [英] Hibernate. PSQLException: bad value for type int : admin

查看:244
本文介绍了休眠。 PSQLException:int类型的错误值:admin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用JAVA和Hibernate 4.3.1 的桌面应用程序。现在我只有两个实体(用户和角色)。



用户



  ... 

@ManyToOne(fetch = FetchType.LAZY)
@Fetch(FetchMode.JOIN)
@JoinColumn(nullable = false,name =fk_role )
private Role fk_role;

...



角色



  ... 

@Column(name =admin,nullable = false)
@Type(type =org .hibernate.type.BooleanType)
private boolean admin = false;

...

我试过了

  @Type(type =org.hibernate.type.BooleanType)

这个。

  @Type(type =org.hibernate.type。 NumericBooleanType)

  @Type(type =org.hibernate.type.YesNoType)

  @Type(type =org.hibernate.type.TrueFalseType)

如下所示: http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/types.html#types-value -basic



什么都没有。 = /



我也试过了: http://alenovarini.wikidot.com/mapping-a-custom-type-in​​-hibernate



=(
在数据库中,列admin的类型是boolean,我使用Postgres 9.3
当我运行它时,我得到以下内容:
-

  org.hibernate.exception.DataException:无法在org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate)执行查询
。 java:135)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java: 126)
at org.hibernate.loader.Loader.doList(Loader.java:2554)
at org.hibernate.loader.Loader.doList(Loader.java:2537)
at org .hibernate.loader.Loader.listIgnoreQueryCach e(Loader.java:2367)
at org.hibernate.loader.Loader.list(Loader.java:2362)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java: 353)
org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1869)
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:311)
at org .hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:141)
at com.print.model.schemaPublic.gateway.UserGateway.list(UserGateway.java:61)
at com.print.model .schemaPublic.UserBusiness.list(UserBusiness.java:22)
at com.print.controller.MenuController.fileNovoAction(MenuController.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method .invoke(Method.java:606)
at com.library.core.ActionListenerDelegate.actionPerformed(ActionListenerDelegate.java:48)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton $ Handler.actionPerformed (AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic。 BasicMenuItemUI $ Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6516)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Compone nt.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container .java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java。 awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access $ 200(EventQueue.java:103 )
at java.awt.EventQueue $ 3.run(EventQueue.java:694)
at java.awt.EventQueue $ 3.run(EventQueue.java:692)
at java.security。 AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain $ 1.doIntersec tionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue $ 4.run(EventQueue.java:708)
在java.awt.EventQueue $ 4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain。 java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt .EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:9 1)

引起:org.postgresql.util.PSQLException:int类型的错误值:admin

解决方案

最后我发现了错误!



Hibernate返回给我的错误消息是类型为int:admin的错误值,但这是问题。关于这个问题,这条消息非常疯狂。 真正的问题是在数据库中我的主键(pk_role)是VARCHAR类型,但在我的实体中我将其作为INTEGER类型。



<在Vlad尝试帮我假设jdbc驱动程序的版本之后,我把配置完全等于我工作得很好的其他项目并且错误是一样的,所以我知道错误是在我自己的代码中,因为肯定。


Well I have a desktop application with JAVA and Hibernate 4.3.1. For now I have just two entities (User and Role).

User

...

@ManyToOne(fetch = FetchType.LAZY)
@Fetch(FetchMode.JOIN)
@JoinColumn(nullable = false, name = "fk_role")
private Role fk_role;

...

Role

...

@Column(name = "admin", nullable = false)
@Type(type = "org.hibernate.type.BooleanType")
private boolean admin = false;

...

I have tried instead

@Type(type = "org.hibernate.type.BooleanType")

this.

@Type(type = "org.hibernate.type.NumericBooleanType")

and

@Type(type = "org.hibernate.type.YesNoType")

and

@Type(type = "org.hibernate.type.TrueFalseType")

As shown here: http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/types.html#types-value-basic

And nothing. =/

I tried this too: http://alenovarini.wikidot.com/mapping-a-custom-type-in-hibernate

=( In the database, the type for column admin is boolean and I use Postgres 9.3. When I run this, I got the following: --

org.hibernate.exception.DataException: could not execute query
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:135)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
    at org.hibernate.loader.Loader.doList(Loader.java:2554)
    at org.hibernate.loader.Loader.doList(Loader.java:2537)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2367)
    at org.hibernate.loader.Loader.list(Loader.java:2362)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:353)
    at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1869)
    at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:311)
    at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:141)
    at com.print.model.schemaPublic.gateway.UserGateway.list(UserGateway.java:61)
    at com.print.model.schemaPublic.UserBusiness.list(UserBusiness.java:22)
    at com.print.controller.MenuController.fileNovoAction(MenuController.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.library.core.ActionListenerDelegate.actionPerformed(ActionListenerDelegate.java:48)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
    at java.awt.Component.processMouseEvent(Component.java:6516)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
    at java.awt.Component.processEvent(Component.java:6281)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4872)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4698)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719)
    at java.awt.Component.dispatchEvent(Component.java:4698)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:708)
    at java.awt.EventQueue$4.run(EventQueue.java:706)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

Caused by: org.postgresql.util.PSQLException: bad value for type int: admin

解决方案

Finally I found the error!

The error message that Hibernate was returning to me was "bad value for type int: admin", but that was not the problem. This message was completely crazy in relation to the issue. The real problem was that in the database my primary key (pk_role) is a VARCHAR type, but in my entity I put as an INTEGER type.

After Vlad try to help me supposing the version of the jdbc driver, I put the configuration exactly equal to other project I have working pretty well and the error was the same, so I knew that the error was in my own code, for sure.

这篇关于休眠。 PSQLException:int类型的错误值:admin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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