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.  [ 9 posts ] 
Author Message
 Post subject: Wrong value of ID
PostPosted: Fri Aug 19, 2005 8:50 am 
Newbie

Joined: Tue Apr 19, 2005 10:15 am
Posts: 8
I used Hibernate a wile and had no problem, but yesterday I was trying to do what I always do, nothing fancy but I'm getting a wrong value for ID. I have primitive class and mapping:
Code:
public class ServerUser{
    private Long id;
    private Long creater;
    private Date created;
    private Long changer;
    private Date changed=new Date();
    private int version;

    private String email;
    private String userName;
    private String password;
//standart getters and setters goes here
}

and mapping:

Code:
<hibernate-mapping>
    <class name="jyaga.vmlo.sign.server.ServerUser" table="sign_user">
        <id name="id" type="long" column="ID">
            <generator class="native"/>
        </id>
        <version name="version" column="VERSION"/>
        <property name="changed" column="CHANGED" type="timestamp"/>
        <property name="changer" column="CHANGER" type="long"/>
      <property name="created" column="CREATED" type="timestamp"/>
        <property name="creater" column="CREATER" type="long"/>

        <property name="email" column="EMAIL" type="string" length="128"/>
        <property name="userName" column="USER_NAME" type="string" length="64"/>
        <property name="password" column="PASSWORD" type="string" length="64"/>
    </class>
</hibernate-mapping>


I use Hibernate 3 with MySQL with standard JDBC connection.
After running the query:
from ServerUser u where u.userName='"+userName+"' and u.password='"+password+"'"
I'm getting an object back and everything is Ok except for id I'm getting wrong value like 7623766823 instead of 7.
I have no idea what could be wrong, as I said I've done a lot such staff and had no problem.
If somebody could clue me in I'd appreciate it.
Thanks,
Eugene


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 9:09 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
So, you're sure that the database value is 7?

It might be the JDBC connector making problems. Which one are you using?
Try out MySQL Connector/J 3.1.10 resp. MySQL Connector/J 3.0.17.

Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 9:28 am 
Newbie

Joined: Tue Apr 19, 2005 10:15 am
Posts: 8
sven wrote:
So, you're sure that the database value is 7?

It might be the JDBC connector making problems. Which one are you using?
Try out MySQL Connector/J 3.1.10 resp. MySQL Connector/J 3.0.17.

Best regards
Sven


Yes, I checked the value of ID in database, it's 7.. and Connector/J is 3.1.10...
BTW: I switched to Java 1.5 recently. Anybody has any problem with this version?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 9:32 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
strokine wrote:
Yes, I checked the value of ID in database, it's 7.. and Connector/J is 3.1.10...
BTW: I switched to Java 1.5 recently. Anybody has any problem with this version?


I'm using Java 5 as well as MySQL and Connector/J 3.1.10 in a certain project without any problems (and many others are using it as well).

Have you already tried to use another version of MySQL Connector/J?
Moreover, post your complete code with the query as well as your POJO.
Database version?

Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:10 am 
Newbie

Joined: Tue Apr 19, 2005 10:15 am
Posts: 8
sven wrote:
I'm using Java 5 as well as MySQL and Connector/J 3.1.10 in a certain project without any problems (and many others are using it as well).

Have you already tried to use another version of MySQL Connector/J?
Moreover, post your complete code with the query as well as your POJO.
Database version?

Best regards
Sven


Are you suggesting to use older version of Connector/J?
here is a code:
Code:
Session s=HibernateUtil.currentSession();
            try{
                List lst=s.createQuery("from jyaga.vmlo.sign.server.ServerUser u where u.userName='"+userName+"' and u.password='"+password+"'").list();
                if(lst!=null && lst.size()>0){
                    ServerUser us=(ServerUser)lst.get(0);
                    String key=userCache.add(us);
                }
            }catch(HibernateException he){
                LogFactory.getLog(LoginServlet.class).error(he,he);
                throw he;
            }finally{
                HibernateUtil.closeSession();
            }

MySQL version is Ver 14.7 Distrib 4.1.10, for Win95/Win98 (i32)

As I said,.. nothing fancy...
I'm lost...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:50 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Or it could be that your mapping file has the id type as long while your class has the id as Long. A subtle but important difference.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 11:07 am 
Newbie

Joined: Tue Apr 19, 2005 10:15 am
Posts: 8
jamie_dainton wrote:
Or it could be that your mapping file has the id type as long while your class has the id as Long. A subtle but important difference.

I don't believed this is the problem, but I changed the type to java.lang.Long in the mapping and result the same...
Thanks, for hint anyway..


Top
 Profile  
 
 Post subject: This happens only with query
PostPosted: Fri Aug 19, 2005 11:14 am 
Newbie

Joined: Tue Apr 19, 2005 10:15 am
Posts: 8
and when I use
Code:
s.load(u,new Long(7));

everything just fine...
[/code]


Top
 Profile  
 
 Post subject: Solution
PostPosted: Fri Aug 19, 2005 11:26 am 
Newbie

Joined: Tue Apr 19, 2005 10:15 am
Posts: 8
Guys, if somebody will have the same problem just make sure your database columns for long type are not unsigned..
when I make them not unsigned everything is well.
I'm just thinking before it works with any type of columns (signed and unsigned) and I don't know since what time it stop working..
Anybody knows how to make it work with unsigned columns?
Thanks,
Eugene


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