-->
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
PostPosted: Fri May 14, 2004 6:36 am 
Newbie

Joined: Tue May 11, 2004 4:44 am
Posts: 5
Hi,
I have a class that that looks like below:
Code:
public class Users {
    public long userId;
    public String username;
    public String password;
    public String realname;
    public String email;
    public String homepage;
    public Date lastLogin;
    public String country;
   
//with the normal getter and setter methods

private static Configuration getConfig() throws HibernateException {
           Configuration config = new Configuration();
               return config.configure();
   }

   private static Session getSession() throws HibernateException {

               Configuration config = getConfig();
               SessionFactory sessionFactory = null;
               Session session = null;
               sessionFactory = config.buildSessionFactory();
               session = sessionFactory.openSession();
               System.out.println("Session value in getSession()" + session.toString());

        return session;
   }

}
//and an add method
public void add() {

       Session session = null;
        try {
            session = getSession();
        } catch (HibernateException he) {
            he.printStackTrace();
        }

       try {
           session.save(this);

           session.flush();
           session.connection().commit();
       } catch (Exception e) {
           e.printStackTrace();
           try {
               session.connection().rollback();
          } catch (Exception e1) {
               e1.printStackTrace();
           }

       }

   }
    public static void main(String [] args ) {

        Users u = new Users();
        u.setUsername("nilesh");
        u.setPassword("parmar");
        u.setRealname("Nilesh");
        u.setEmail("nilesh@pramati.com");
        u.setHomepage("localhost");
        u.setCountry("counteryName");
        u.setEmail("nilesh@pramati.com");
        Date today = new Date(System.currentTimeMillis());
        u.setLastLogin(today);
        u.add();

    }


Here is the hibernate mapping:
Code:
<hibernate-mapping>
    <class name="org.weblog.user.Users" table="weblog_users">
        <id name = "userId" type ="int" column="userId">
            <generator class = "increment" />
        </id>
        <property name = "username"         type ="string"       column ="username"       length="40"/>
        <property name = "password"         type ="string"       column ="password"    length="30"/>
        <property name = "realname"         type ="string"       column ="realname"    length="80"/>
        <property name = "email"            type ="string"       column ="email"       length="50"/>
        <property name = "homepage"         type ="string"       column ="homePage"    length="80"/>
        <property name = "lastLogin"        type ="date"     column ="lasgLogin"   />
        <property name = "country"          type ="string"       column ="country"     length="80"/>
    </class>
</hibernate-mapping>


When i run the above code i get the following exception:
Code:
Hibernate: insert into weblog_users (username, password, realname, email, homePage, lasgLogin, country, userId) values (?, ?, ?, ?, ?, ?, ?, ?)
java.lang.ClassCastException
   at net.sf.hibernate.type.IntegerType.set(IntegerType.java:27)
   at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:46)
   at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:31)
   at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:377)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:476)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:454)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:20)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2100)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2061)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
   at org.weblog.user.Users.add(Users.java:129)
   at org.weblog.user.Users.main(Users.java:323)


Can anyone please help me ? I'm not sure if my mappings are correct.


Top
 Profile  
 
 Post subject: Re: ClassCastException
PostPosted: Fri May 14, 2004 6:42 am 
Regular
Regular

Joined: Wed Apr 21, 2004 10:57 am
Posts: 62
Location: Hasselt, Belgium
public longuserId;

<id name = "userId" type ="int" column="userId">
<generator class = "increment" />
</id>

Not to sure this is the problem but shouldn't this be the same?

Peter


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.