为了账号安全,请及时绑定邮箱和手机立即绑定

java.math.BigInteger cannot be cast to java.lang.Long求大神指点

十一月 02, 2018 3:14:54 上午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>

INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}

十一月 02, 2018 3:14:54 上午 org.hibernate.Version logVersion

INFO: HHH000412: Hibernate Core {4.3.0.Final}

十一月 02, 2018 3:14:54 上午 org.hibernate.cfg.Environment <clinit>

INFO: HHH000206: hibernate.properties not found

十一月 02, 2018 3:14:54 上午 org.hibernate.cfg.Environment buildBytecodeProvider

INFO: HHH000021: Bytecode provider name : javassist

十一月 02, 2018 3:14:54 上午 org.hibernate.cfg.Configuration configure

INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml

十一月 02, 2018 3:14:54 上午 org.hibernate.cfg.Configuration getConfigurationInputStream

INFO: HHH000040: Configuration resource: /hibernate.cfg.xml

十一月 02, 2018 3:14:54 上午 org.hibernate.cfg.Configuration addResource

INFO: HHH000221: Reading mappings from resource: com/imooc/entity/Grade.hbm.xml

十一月 02, 2018 3:14:54 上午 org.hibernate.cfg.Configuration addResource

INFO: HHH000221: Reading mappings from resource: com/imooc/entity/Student.hbm.xml

十一月 02, 2018 3:14:54 上午 org.hibernate.cfg.Configuration doConfigure

INFO: HHH000041: Configured SessionFactory: null

十一月 02, 2018 3:14:54 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)

十一月 02, 2018 3:14:54 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/imooc?useUnicode=true&characterEncoding=utf8]

十一月 02, 2018 3:14:54 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH000046: Connection properties: {user=root, password=****}

十一月 02, 2018 3:14:54 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator

INFO: HHH000006: Autocommit mode: false

十一月 02, 2018 3:14:54 上午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure

INFO: HHH000115: Hibernate connection pool size: 20 (min=1)

Exception in thread "main" java.lang.ExceptionInInitializerError

at com.imooc.test.Test.add(Test.java:36)

at com.imooc.test.Test.main(Test.java:22)

Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect

at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:122)

at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:140)

at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:58)

at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:75)

at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)

at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)

at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)

at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)

at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)

at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)

at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)

at com.imooc.util.HibernateUtil.<clinit>(HibernateUtil.java:19)

... 2 more

Caused by: java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)

at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1074)

at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3590)

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2531)

at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301)

at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)

at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)

at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)

at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:55)

... 15 more

Caused by: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long

at com.mysql.jdbc.ConnectionImpl.buildCollationMapping(ConnectionImpl.java:1019)

... 28 more


正在回答

1 回答

java.math.BigInteger cannot be cast to java.lang.Long

就是类型不能转换,你看看你定义的id是什么类型的改一下,要么改类里的,要么改你数据库的表里的

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Hibernate初探之一对多映射
  • 参与学习       42169    人
  • 解答问题       295    个

Hibernate中一对多关联映射配置,以及cascade和inverse属性作用

进入课程

java.math.BigInteger cannot be cast to java.lang.Long求大神指点

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信