-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Annotated model with a BigInteger @Id column
PostPosted: Thu Feb 11, 2010 12:55 am 
Newbie

Joined: Thu Feb 11, 2010 12:48 am
Posts: 3
Hello,

I'm developing for a legacy database with ID's generated in code. Because of the way the ID generator is written I require a BigInteger (or BigDecimal) @Id column.

Currently attempting this is throwing the error:
Code:
org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type for class my.package.name.MyModel. Expected: class java.math.BigInteger, got class java.lang.Long; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type for class my.package.name.MyModel. Expected: class java.math.BigInteger, got class java.lang.Long
   at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679)
   at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
   at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
   at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:512)
   at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:506)
   at my.package.name.MyModelDao.get(MyModelDao.java:45)
   at my.package.name.MyModelDaoTest.testGetModel(MyModelDaoTest.java:17)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
   at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
   at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
   at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
   at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
   at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
   at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
   at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
   at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.TypeMismatchException: Provided id of the wrong type for class my.package.name.MyModel. Expected: class java.math.BigInteger, got class java.lang.Long
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:109)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:842)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:835)
   at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:519)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
   ... 33 more


Am I doing something wrong? Is there a work around?
I'm stuck with the current ID generation, short of a complete overhaul of a government system.

Thanks,
Danny.


Top
 Profile  
 
 Post subject: Re: Annotated model with a BigInteger @Id column
PostPosted: Thu Feb 11, 2010 3:51 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Just the stacktrace may not be any good. It would help if you also posted your code that leads up to the error and your annotated entity classes.

In any case, it seems like you are trying to load an entity with the get() method. Are you passing a BigInteger object to get()?


Top
 Profile  
 
 Post subject: Re: Annotated model with a BigInteger @Id column
PostPosted: Thu Feb 11, 2010 7:00 am 
Newbie

Joined: Thu Feb 11, 2010 12:48 am
Posts: 3
Argh, that's so the problem. I'm away from the PC at the moment, but guaranteed I'm calling get with a Long instead of a BigInteger.
I was busy playing with the annotations instead of looking at the test case.

Searching around there were a fair few people complaining of Hibernate not supporting BigInteger for ID's, giving an error along the lines of "id types can only be string, int, long..." etc. so I instantly assumed I was hitting the same issue.

Thanks a bunch, knowing me I'll forget about this topic if I try it tomorrow and all works. If not I'll be back ranting :)


Top
 Profile  
 
 Post subject: Re: Annotated model with a BigInteger @Id column
PostPosted: Thu Feb 11, 2010 7:09 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Hmmm... you can use BigInteger as id, but not all id generators support it. Among the built-in gnerators it may only be the 'assigned' generator that you can use. See http://docs.jboss.org/hibernate/stable/ ... aration-id) for more information.


Top
 Profile  
 
 Post subject: Re: Annotated model with a BigInteger @Id column
PostPosted: Thu Feb 11, 2010 8:07 am 
Newbie

Joined: Thu Feb 11, 2010 12:48 am
Posts: 3
Great, thanks for the info. I'm currently using my own generator (although untested given the errors above), which basically just makes a call to the legacy IDGenerator class returning a BigInteger from generate(...).

That should hopefully avoid any issues. Will see in 9 hours or so :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.