-->
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.  [ 2 posts ] 
Author Message
 Post subject: StringType ClassCastException during merge()
PostPosted: Thu Jun 08, 2006 10:31 am 
Beginner
Beginner

Joined: Sun Jul 10, 2005 12:11 pm
Posts: 32
Location: Hertfordshire, England
I'd like help with this obscure error. I have solved it, but am not sure why the error occurred - I'm also sure that hibernate should give a more meaningful error in this case anyway!

The solution is documented as a second post to this one.

Thanks in advance.

Hibernate version:
3.0.5

Mapping documents:
I'm not including all (they're huge) but see below for relevent snippets (generated using xdoclet):

Employees object:
Code:
       
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="Employees" table="PS_EMPLOYEES">

    <id name="emplid" column="EMPLID" type="java.lang.String">
        <generator class="assigned"/>
    </id>

<snip>
    <one-to-one
            name="access"
            class="Access"
            cascade="save-update"
            fetch="join"
            property-ref="employee"
            lazy="true"/>
<snip>

</hibernate-mapping>


Access object:
Code:
       
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="Access" table="PS_ACCESS">

    <id name="emplid" column="EMPLID">
        <generator class="assigned"/>
    </id>

<snip>
        <many-to-one name="employee"
                column="emplid"
                not-null="true"
                unique="true"
                insert="false"
                update="false"/>
<snip>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Again not a complete example, but what I am doing is:

Edit an employee object in a long-standing session used only for reading, never updating.
Merge that object into a newly created session as follows:
Code:
editSession = HibernateUtil.currentSession("EditHierarchyNode");
Transaction tx = editSession.beginTransaction();
Employees editEE = (Employees) editSession.merge(employee);

The error occurs on this line (merge) - see stack trace below.

Full stack trace of any exception that occurs:
Exception occurred during event dispatching:
java.lang.ClassCastException: Employees$$EnhancerByCGLIB$$39ecb751
at org.hibernate.type.StringType.set(StringType.java:24)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1115)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1177)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1345)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:106)
at org.hibernate.persister.entity.BasicEntityPersister.loadByUniqueKey(BasicEntityPersister.java:1333)
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:343)
at org.hibernate.type.EntityType.resolve(EntityType.java:289)
at org.hibernate.type.EntityType.replace(EntityType.java:197)
at org.hibernate.type.TypeFactory.replace(TypeFactory.java:385)
at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:239)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:224)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:102)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:54)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:539)
at EditNodeDialog$RowWidgets.saveRow(EditNodeDialog.java:340)
at EditNodeDialog.actionPerformed(EditNodeDialog.java:194)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:153)
at java.awt.Dialog$1.run(Dialog.java:515)
at java.awt.Dialog.show(Dialog.java:536)
at java.awt.Component.show(Component.java:1300)
at java.awt.Component.setVisible(Component.java:1253)
at EditNodeDialog.createDialog(EditNodeDialog.java:172)
at HierarchyBuilder.makeEditDialog(HierarchyBuilder.java:277)
at HierarchyBuilder.access$2(HierarchyBuilder.java:273)
at HierarchyBuilder$2.mouseClicked(HierarchyBuilder.java:328)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
at java.awt.Component.processMouseEvent(Component.java:5491)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3901)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Name and version of the database you are using:
Oracle 9i with latest oracle classes12.jar.

The generated SQL (show_sql=true):
Error occurs just after:
Code:
Hibernate: select access0_.EMPLID as EMPLID0_, access0_.emplid as emplid14_0_, access0_.P1_ADMIN as P13_14_0_, access0_.P2_ADMIN as P24_14_0_, access0_.P3_ADMIN as P35_14_0_, access0_.LAST_LOGIN_DATE as LAST6_14_0_, access0_.LAST_PW_CHANGE_DATE as LAST7_14_0_, access0_.P1_ESPS as P18_14_0_, access0_.P2_ESPS as P29_14_0_, access0_.P3_ESPS as P310_14_0_, access0_.USE_CONDITIONS_ACCEPTED as USE11_14_0_, access0_.P1_EMP as P112_14_0_, access0_.P2_EMP as P213_14_0_, access0_.P3_EMP as P314_14_0_ from db_name.PS_ACCESS access0_ where access0_.emplid=?

Debug level Hibernate log excerpt:
Information above.

_________________
--
Christian Ashby
Spiralinks, Inc.


Last edited by cscashby on Thu Jun 08, 2006 3:21 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Solution to above problem
PostPosted: Thu Jun 08, 2006 10:33 am 
Beginner
Beginner

Joined: Sun Jul 10, 2005 12:11 pm
Posts: 32
Location: Hertfordshire, England
The problem was solved by changing:
Code:
cascade="save-update"

to:
Code:
cascade="all"

In the Employees object.

Could someone point toward why this error occured with a save-update cascade option?

_________________
--
Christian Ashby
Spiralinks, Inc.


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