-->
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: ClassCastException with Integer Index in a Map
PostPosted: Wed Sep 01, 2004 3:45 pm 
Newbie

Joined: Wed Sep 01, 2004 3:02 pm
Posts: 2
Location: Connecticut
Hi all,

Very new to Hibernate, and I've looked around the forums, but didn't see anything on this issue, so please excuse me if it's already been addressed elsewhere.

I have a feeling that this may have something to do with the MS SQL Server rather than Hibernate, or an issue with the way I've mapped it.

In my test application, I have a User and a Group object both very simple objects with an Id and a Description. I was successfully able to load, save, delete them with Hibernate (which was quite exciting), but now I'm trying to setup the many-to-many relationship between the two, and am experiencing issues.

The problem is that it runs normally, but when it calls session.save(user2); it just hangs. I actually timeout everytime I try to open my table through the MS SQL Enterprise Manager tool.

I'm using Eclipse 2.1 and Ant 1.6.1 to run my code. Does anyone know of any issues anything that would cause this? I'm going to try the standard Microsoft reboot (probably should have before I started putting this post together, but I've already typed too much already!).

Lousy Microsoft!

Please let me know though if anyone can determine what might be going on here. Thanks!
-Brian-

Here's the details:

Hibernate version: 21

Mapping documents:
Code:
<class name="User" table="Users">
    ..............
    <map name="groups" table="Group_Users">
       <key column="userId"/>
       <index column="groupUserId" type="[color=red]integer[/color]"/>
       <many-to-many column="groupId" class="Group"/>
    </map>
</class>

<class name="User" table="Users">
    ............
    <map name="individuals" table="Group_Users">
       <key column="groupId"/>
       <index column="groupUserId" type="[color=red]integer[/color]"/>
       <many-to-many column="userId" class="User"/>
    </map>
</class>


Map Code in User and Group Objects
Code:
public class Group(){
    ..........   
    public void setIndividuals(Map users){ individuals.putAll(users); }
    public Map getIndividuals(){ return individuals; }
    public void addIndividual(User user){ individuals.put( user.getId(), user );}
    public void removeIndividual(User user){ individuals.remove( user ); }

    private Map individuals = new TreeMap();
}

public class User(){
    .........
    public void setGroups(Map newGroups){ groups.putAll(newGroups); }
    public Map getGroups(){ return groups; }
    public void addGroup(Group group){ groups.put( new Integer(group.getId()), group ); }
    public void removeGroup(Group group){ groups.remove( group ); }

    private Map groups= new TreeMap();
}


Code between sessionFactory.openSession() and session.close():
Code:
SessionFactory sessions = new Configuration().configure().buildSessionFactory();
    Session session = sessions.openSession();
             
    Transaction tx = null;

    Group csrs = new Group("csrs");   

    User user2 = new User("csrtest");
    user2.setFirst("CSR");
    user2.setLast("Tester");
    user2.setEmail("briley@personix.fiserv.com");

    csrs.addIndividual(user2);

    tx = session.beginTransaction();
        session.save( user2 );
        session.save( csrs );
    tx.commit();

    session.close();


Full stack trace:
Code:
[java] java.lang.ClassCastException
        [java]    at net.sf.hibernate.type.IntegerType.set(IntegerType.java:31)
        [java]    at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
        [java]    at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
        [java]    at net.sf.hibernate.collection.AbstractCollectionPersister.writeIndex(AbstractCollectionPersister.java:394)
        [java]    at net.sf.hibernate.collection.Map.writeTo(Map.java:193)
        [java]    at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:523)
        [java]    at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
        [java]    at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
        [java]    at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2371)
        [java]    at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
        [java]    at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
        [java]    at com.personix.wc3.test.persistTest.main(persistTest.java:78)
        [java]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        [java]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        [java]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        [java]    at java.lang.reflect.Method.invoke(Unknown Source)
        [java]    at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:208)
        [java]    at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:150)
        [java]    at org.apache.tools.ant.taskdefs.Java.run(Java.java:443)
        [java]    at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:163)
        [java]    at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
        [java]    at org.apache.tools.ant.Task.perform(Task.java:341)
        [java]    at org.apache.tools.ant.Target.execute(Target.java:309)
        [java]    at org.apache.tools.ant.Target.performTasks(Target.java:336)
        [java]    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
        [java]    at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
        [java]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:569)
        [java]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:367)
        [java]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        [java]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        [java]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        [java]    at java.lang.reflect.Method.invoke(Unknown Source)
        [java]    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:335)
        [java]    at org.eclipse.ui.externaltools.internal.ant.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:172)
        [java]    at java.lang.Thread.run(Unknown Source)
        [java] Sep 1, 2004 3:11:30 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: SQL Warning: 0, SQLState:
        [java] Sep 1, 2004 3:11:30 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to HibernateTest
        [java] Sep 1, 2004 3:11:30 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: SQL Warning: 0, SQLState:
        [java] Sep 1, 2004 3:11:30 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed database context to 'HibernateTest'.
        [java] Sep 1, 2004 3:11:30 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: SQL Warning: 0, SQLState:
        [java] Sep 1, 2004 3:11:30 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to us_english
        [java] Sep 1, 2004 3:11:30 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: SQL Warning: 0, SQLState:
        [java] Sep 1, 2004 3:11:30 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed language setting to us_english.


Name and version of the database you are using: SQL Server 2000
Code:
Table Group_Users detail:
groupUserId - int - not Nullable - PK (tried both as an SQL Server identity, and a regular int)
userId - int - Not Nullable
groupId - int - Not Nullable


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 01, 2004 3:57 pm 
Newbie

Joined: Wed Sep 01, 2004 3:02 pm
Posts: 2
Location: Connecticut
Ok, rebooted, checked the MS SQL tables and was able to open them, then I reran and got the following:

Code:
[java] java.lang.ClassCastException
        [java]    at net.sf.hibernate.type.IntegerType.set(IntegerType.java:31)
        [java]    at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
        [java]    at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
        [java]    at net.sf.hibernate.collection.AbstractCollectionPersister.writeIndex(AbstractCollectionPersister.java:394)
        [java]    at net.sf.hibernate.collection.Map.writeTo(Map.java:193)
        [java]    at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:523)
        [java]    at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
        [java]    at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
        [java]    at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2371)
        [java]    at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
        [java]    at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
        [java]    at com.personix.wc3.test.persistTest.main(persistTest.java:78)
        [java]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        [java]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        [java]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        [java]    at java.lang.reflect.Method.invoke(Unknown Source)
        [java]    at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:208)
        [java]    at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:150)
        [java]    at org.apache.tools.ant.taskdefs.Java.run(Java.java:443)
        [java]    at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:163)
        [java]    at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
        [java]    at org.apache.tools.ant.Task.perform(Task.java:341)
        [java]    at org.apache.tools.ant.Target.execute(Target.java:309)
        [java]    at org.apache.tools.ant.Target.performTasks(Target.java:336)
        [java]    at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
        [java]    at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
        [java]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:569)
        [java]    at org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:367)
        [java]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        [java]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        [java]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        [java]    at java.lang.reflect.Method.invoke(Unknown Source)
        [java]    at org.eclipse.ant.core.AntRunner.run(AntRunner.java:335)
        [java]    at org.eclipse.ui.externaltools.internal.ant.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:172)
        [java]    at java.lang.Thread.run(Unknown Source)
        [java] Sep 1, 2004 3:51:28 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: SQL Warning: 0, SQLState:
        [java] Sep 1, 2004 3:51:28 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to HibernateTest
        [java] Sep 1, 2004 3:51:28 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: SQL Warning: 0, SQLState:
        [java] Sep 1, 2004 3:51:28 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed database context to 'HibernateTest'.
        [java] Sep 1, 2004 3:51:28 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: SQL Warning: 0, SQLState:
        [java] Sep 1, 2004 3:51:28 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to us_english
        [java] Sep 1, 2004 3:51:28 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: SQL Warning: 0, SQLState:
        [java] Sep 1, 2004 3:51:28 PM net.sf.hibernate.util.JDBCExceptionReporter logWarnings
        [java] WARNING: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed language setting to us_english.


Correction to my previous post: the userId metioned in the table is a varchar(10) not an int.

I think it's the <index column="groupUserId" type="integer"> that's causing me grief. Any ideas?


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.