-->
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.  [ 3 posts ] 
Author Message
 Post subject: IdentifierGeneratorFactory cannot be cast to java.lang.Long
PostPosted: Fri Dec 21, 2007 1:48 pm 
Newbie

Joined: Fri Dec 21, 2007 1:37 pm
Posts: 2
Hi there
I really don't understand what's going on, or what to do.
identity seems to be the only valid generator, and It seems it gives back a Serializable object.
When I use type="serializable" I can't create the table because it tries to create a tinyblog with auto_increment.
any ideas ?
Thank you !

Hibernate version:3.2.0.ga

Mapping documents:
@OneToMany(cascade = CascadeType.ALL)
@CollectionId(columns = @Column(name="id"),type=@Type(type="long"),generator = "identity")



Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
java.lang.ClassCastException: org.hibernate.id.IdentifierGeneratorFactory$2 cannot be cast to java.lang.Long
at org.hibernate.type.LongType.set(LongType.java:42)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeIdentifier(AbstractCollectionPersister.java:807)
at org.hibernate.persister.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:1359)
at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
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.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy14.flush(Unknown Source)
at com.newco.leadmachine.action.AddWebSite.execute(AddWebSite.java:52)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)


Name and version of the database you are using:Mysql 5


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 2:23 pm 
Newbie

Joined: Fri Dec 21, 2007 1:37 pm
Posts: 2
I have found something that seems to work, though I still don't understand what was the previous problem ...

you have to use a GenericGenerator something like :

@GenericGenerator(name = "gg1",strategy = "increment")
@CollectionId(columns = @Column(name="id"),type=@Type(type="long"),generator = "gg1")

Hope it will help someone else !

Cheers.


Top
 Profile  
 
 Post subject: Re: IdentifierGeneratorFactory cannot be cast to java.lang.Long
PostPosted: Mon Aug 29, 2011 3:02 am 
Newbie

Joined: Mon Aug 29, 2011 2:55 am
Posts: 1
Using increment is wroking fine, But i want to know why it's not working with native or sequence. For my Mysql database
i want to use native. don't want incriment and my mapping code is

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.ssis.model.Item2" table="item2">
<id name="itemId">
<generator class="native"></generator>
</id>
<idbag name="images" table="timage2">
<collection-id type="long" column="imageid" >
<generator class="native"></generator>
</collection-id>
<key column="itemId"></key>
<element type="string" column="filename"></element>
</idbag>
<property name="name"></property>
<property name="price"></property>
</class>
</hibernate-mappinv>

Can any one please answer . why I'm getting

Hibernate: insert into item2 (name, price) values (?, ?)
Hibernate: insert into timage2 (itemId, imageid, filename) values (?, ?, ?)
Exception in thread "main" java.lang.ClassCastException: org.hibernate.id.IdentifierGeneratorFactory$2 cannot be cast to java.lang.Long
at org.hibernate.type.LongType.set(LongType.java:65)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeIdentifier(AbstractCollectionPersister.java:829)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1160)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at ItemTest.main(ItemTest.java:24)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.