-->
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: Strange values bound to LongType :: Causing ObjectNotFound
PostPosted: Thu Jan 26, 2006 5:14 pm 
Newbie

Joined: Thu Jan 26, 2006 4:59 pm
Posts: 2
I'm having trouble tracking down how LongTypes in the 4 billion range are being returned to hibernate. When I execute the query by hand in mysql I get results:

+----------+
| col_0_0_ |
+----------+
| 1000 |
| 1974 |
| 3473 |
| 4338 |
| 6519 |
| 6520 |
+----------+
6 rows in set (0.00 sec)

What I see in my DEBUG logs are snippets like:

15:50:39,985 DEBUG AbstractBatcher:424 - preparing statement
15:50:40,031 DEBUG AbstractBatcher:327 - about to open ResultSet (open ResultSets: 0, globally: 0)
15:50:40,035 DEBUG IteratorImpl:89 - retrieving next results
15:50:40,036 DEBUG LongType:123 - returning '4294967772' as column: col_0_0_
15:50:40,042 DEBUG DefaultLoadEventListener:153 - loading entity: [edu.purdue.pkr.orm.pkr.KsdAlignment#4294967772]
15:50:40,043 DEBUG DefaultLoadEventListener:230 - creating new proxy for entity
15:50:40,065 DEBUG IteratorImpl:89 - retrieving next results

Where '4294967772' is being returned as the value for col_0_0_, and thus ObjectNotFoundExceptions are being thrown, because the actual IDs are nohwere near 4 billion.

Hibernate version: 3.1.1, (tried with 3.0.5 as well)

Mapping documents:

<?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 schema="pkr">
<class name="edu.purdue.pkr.orm.pkr.KsdAlignment" table="ksd_alignment" >
<id name="masterUniprot_n" column="master_uniprot_n"
type="java.lang.Long" unsaved-value="null">
<generator class="assigned"/>
</id>
<property
name="proteinSequenceId" column="protein_sequence_id" type="java.lang.Long"
not-null="true" unique="false" />
<property
name="substringOffset" column="substring_offset" type="java.lang.Integer"
not-null="true" unique="false" />
<property
name="substringLength" column="substring_length" type="java.lang.Integer"
not-null="true" unique="false" />
<property
name="substringAligned" column="substring_aligned" type="org.hibernate.type.TextType"
not-null="true" unique="true" />
</class>
</hibernate-mapping>

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


Session hbnsession = HibernateUtils.getSession();
Transaction tx = hbnsession.beginTransaction();

log.debug("Alignment service: ids = " + ids);

StringBuffer hqlbuffer = new StringBuffer("FROM edu.purdue.pkr.orm.pkr.KsdAlignment ksd " + "WHERE ksd.masterUniprot_n = " + ids.get(0));

for (int i = 1; i < ids.size(); i++) {
hqlbuffer.append(" OR ksd.masterUniprot_n = " + ids.get(i));
}


Query query = hbnsession.createQuery(hqlbuffer.toString());

HashMap alignedSeq = new HashMap();
Vector names = new Vector();

for (Iterator it = query.iterate(); it.hasNext();) {
KsdAlignment ksdAlignment = (KsdAlignment) it.next();
// System.out.println(ksdAlignment.getMasterUniprot_n());
names.add(ksdAlignment.getMasterUniprot_n().toString());
alignedSeq.put(ksdAlignment.getMasterUniprot_n().toString(), ksdAlignment.getSubstringAligned());
}
tx.commit();
HibernateUtils.closeSession();



Full stack trace of any exception that occurs:

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [edu.purdue.pkr.orm.pkr.KsdAlignment#4294967772]
at org.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:27)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:65)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
(...)

Name and version of the database you are using: MySQL 5.0.16 (linux)

The generated SQL (show_sql=true):

select ksdalignme0_.master_uniprot_n as col_0_0_ from pkr.ksd_alignment ksdalignme0_ where ksdalignme0_.master_uniprot_n=1000 or ksdalignme0_.master_uniprot_n=4338 or ksdalignme0_.master_uniprot_n=3473 or ksdalignme0_.master_uniprot_n=6520 or ksdalignme0_.master_uniprot_n=1974 or ksdalignme0_.master_uniprot_n=6519

which generates results to be iteratively applied to:


select ksdalignme0_.master_uniprot_n as master1_9_0_, ksdalignme0_.protein_sequence_id as protein2_9_0_, ksdalignme0_.substring_offset as substring3_9_0_, ksdalignme0_.substring_length as substring4_9_0_, ksdalignme0_.substring_aligned as substring5_9_0_ from pkr.ksd_alignment ksdalignme0_ where ksdalignme0_.master_uniprot_n=?

Debug level Hibernate log excerpt:

15:50:40,076 DEBUG AbstractBatcher:424 - preparing statement
15:50:40,078 DEBUG LongType:79 - binding '4294967772' to parameter: 1
15:50:40,079 DEBUG AbstractBatcher:327 - about to open ResultSet (open ResultSets: 1, globally: 1)
15:50:40,080 DEBUG Loader:682 - processing result set
15:50:40,081 DEBUG Loader:709 - done processing result set (0 rows)
15:50:40,082 DEBUG AbstractBatcher:334 - about to close ResultSet (open ResultSets: 2, globally: 2)
15:50:40,082 DEBUG AbstractBatcher:319 - about to close PreparedStatement (open PreparedStatements: 2, globally: 2)
15:50:40,083 DEBUG AbstractBatcher:470 - closing statement
15:50:40,086 DEBUG Loader:839 - total objects hydrated: 0
15:50:40,088 DEBUG StatefulPersistenceContext:820 - initializing non-lazy collections
15:50:40,088 DEBUG Loader:1808 - done entity load
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [edu.purdue.pkr.orm.pkr.KsdAlignment#4294967772]





Any help is much appreciated!


Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 12:53 pm 
Newbie

Joined: Thu Jan 26, 2006 4:59 pm
Posts: 2
I have some updated information, and have found a workaround for my problem --> Namely, do not use Unsigned Int's with the java.lang.Long.

[I'm not claiming that I'm not doing anything else totally wrong!]

I wrote this small test program.


So, in my test program, I could see that Val4, was returned with incorrect results, actually, they are correct, if you apply this formula:

2^32 - (returned answer) = - (expected answer)


Anyone have any ideas?

Relevant information:

MySQL version: 5.0.16 (linux)
Connector/J: 3.1.10
Hibernate: 3.1.1
Java: 1.5.0_05

... So at this point I'd just like to know if it's likely that I'm doing something wrong, or if something is out of date, or if there is an odd software / bug configuration.



Thanks!


Code:
/*
Results form RuN:
Hibernate: select hbntest0_.val1 as col_0_0_ from pkr.hbntest hbntest0_
Hibernate: select hbntest0_.val1 as val1_1_0_, hbntest0_.val2 as val2_1_0_, hbntest0_.val3 as val3_1_0_, hbntest0_.val4 as val4_1_0_, hbntest0_.val5 as val5_1_0_, hbntest0_.val6 as val6_1_0_, hbntest0_.val7 as val7_1_0_, hbntest0_.val8 as val8_1_0_ from pkr.hbntest hbntest0_ where hbntest0_.val1=?
0,0,0,4294967296,0,0,0,0

Hibernate: select hbntest0_.val1 as val1_1_0_, hbntest0_.val2 as val2_1_0_, hbntest0_.val3 as val3_1_0_, hbntest0_.val4 as val4_1_0_, hbntest0_.val5 as val5_1_0_, hbntest0_.val6 as val6_1_0_, hbntest0_.val7 as val7_1_0_, hbntest0_.val8 as val8_1_0_ from pkr.hbntest hbntest0_ where hbntest0_.val1=?
1,1,1,4294967297,1,1,1,1

Hibernate: select hbntest0_.val1 as val1_1_0_, hbntest0_.val2 as val2_1_0_, hbntest0_.val3 as val3_1_0_, hbntest0_.val4 as val4_1_0_, hbntest0_.val5 as val5_1_0_, hbntest0_.val6 as val6_1_0_, hbntest0_.val7 as val7_1_0_, hbntest0_.val8 as val8_1_0_ from pkr.hbntest hbntest0_ where hbntest0_.val1=?
2,2,2,4294967298,2,2,2,2

Hibernate: select hbntest0_.val1 as val1_1_0_, hbntest0_.val2 as val2_1_0_, hbntest0_.val3 as val3_1_0_, hbntest0_.val4 as val4_1_0_, hbntest0_.val5 as val5_1_0_, hbntest0_.val6 as val6_1_0_, hbntest0_.val7 as val7_1_0_, hbntest0_.val8 as val8_1_0_ from pkr.hbntest hbntest0_ where hbntest0_.val1=?
3,3,3,4294967299,3,3,3,3

Hibernate: select hbntest0_.val1 as val1_1_0_, hbntest0_.val2 as val2_1_0_, hbntest0_.val3 as val3_1_0_, hbntest0_.val4 as val4_1_0_, hbntest0_.val5 as val5_1_0_, hbntest0_.val6 as val6_1_0_, hbntest0_.val7 as val7_1_0_, hbntest0_.val8 as val8_1_0_ from pkr.hbntest hbntest0_ where hbntest0_.val1=?
4,4,4,4294967300,4,4,4,4

Hibernate: select hbntest0_.val1 as val1_1_0_, hbntest0_.val2 as val2_1_0_, hbntest0_.val3 as val3_1_0_, hbntest0_.val4 as val4_1_0_, hbntest0_.val5 as val5_1_0_, hbntest0_.val6 as val6_1_0_, hbntest0_.val7 as val7_1_0_, hbntest0_.val8 as val8_1_0_ from pkr.hbntest hbntest0_ where hbntest0_.val1=?
5,5,5,4294967301,5,5,5,5

Hibernate: select hbntest0_.val1 as val1_1_0_, hbntest0_.val2 as val2_1_0_, hbntest0_.val3 as val3_1_0_, hbntest0_.val4 as val4_1_0_, hbntest0_.val5 as val5_1_0_, hbntest0_.val6 as val6_1_0_, hbntest0_.val7 as val7_1_0_, hbntest0_.val8 as val8_1_0_ from pkr.hbntest hbntest0_ where hbntest0_.val1=?
6,6,6,4294967302,6,6,6,6

Hibernate: select hbntest0_.val1 as val1_1_0_, hbntest0_.val2 as val2_1_0_, hbntest0_.val3 as val3_1_0_, hbntest0_.val4 as val4_1_0_, hbntest0_.val5 as val5_1_0_, hbntest0_.val6 as val6_1_0_, hbntest0_.val7 as val7_1_0_, hbntest0_.val8 as val8_1_0_ from pkr.hbntest hbntest0_ where hbntest0_.val1=?
7,7,7,4294967303,7,7,7,7

Hibernate: select hbntest0_.val1 as val1_1_0_, hbntest0_.val2 as val2_1_0_, hbntest0_.val3 as val3_1_0_, hbntest0_.val4 as val4_1_0_, hbntest0_.val5 as val5_1_0_, hbntest0_.val6 as val6_1_0_, hbntest0_.val7 as val7_1_0_, hbntest0_.val8 as val8_1_0_ from pkr.hbntest hbntest0_ where hbntest0_.val1=?
8,8,8,4294967304,8,8,8,8
*/


/*
<hibernate-mapping schema="pkr">
    <class name="HBNTest" table="hbntest" >
        <id  name="val1" column="val1" type="java.lang.Integer" unsaved-value="null">
            <generator class="assigned"/>
        </id>
        <property name="val2" column="val2" type="java.lang.Integer" not-null="false" unique="false" />
        <property name="val3" column="val3" type="java.lang.Long" not-null="false" unique="false" />
        <property name="val4" column="val4" type="java.lang.Long" not-null="false" unique="false" />
        <property name="val5" column="val5" type="java.lang.Integer" not-null="false" unique="false" />
        <property name="val6" column="val6" type="java.lang.Integer" not-null="false" unique="false" />
        <property name="val7" column="val7" type="java.lang.Long" not-null="false" unique="false" />
        <property name="val8" column="val8" type="java.lang.Long" not-null="false" unique="false" />
    </class>
</hibernate-mapping>

-------------

Schema:

drop table if exists hbntest;
create table hbntest (
    val1 integer not null primary key,
    val2 integer unsigned,
    val3 integer,
    val4 integer unsigned,
    val5 bigint,
    val6 bigint unsigned,
    val7 bigint,
    val8 bigint unsigned
);
insert into hbntest values (0,0,0,0,0,0,0,0);
insert into hbntest values (1,1,1,1,1,1,1,1);
insert into hbntest values (2,2,2,2,2,2,2,2);
insert into hbntest values (3,3,3,3,3,3,3,3);
insert into hbntest values (4,4,4,4,4,4,4,4);
insert into hbntest values (5,5,5,5,5,5,5,5);
insert into hbntest values (6,6,6,6,6,6,6,6);
insert into hbntest values (7,7,7,7,7,7,7,7);
insert into hbntest values (8,8,8,8,8,8,8,8);
*/
public class HBNTest implements Serializable {
    private Integer val1;
    private Integer val2;
    private Long    val3;
    private Long    val4;
    private Integer val5;
    private Integer val6;
    private Long    val7;
    private Long    val8;


    public Integer getVal1() { return val1; }
    public Integer getVal2() { return val2; }
    public Integer getVal5() { return val5; }
    public Integer getVal6() { return val6; }

    public void setVal1(Integer n) { val1 = n; }
    public void setVal2(Integer n) { val2 = n; }
    public void setVal5(Integer n) { val5 = n; }
    public void setVal6(Integer n) { val6 = n; }


    public Long getVal3() { return val3; }
    public Long getVal4() { return val4; }
    public Long getVal7() { return val7; }
    public Long getVal8() { return val8; }

    public void setVal3(Long n) { val3 = n; }
    public void setVal4(Long n) { val4 = n; }
    public void setVal7(Long n) { val7 = n; }
    public void setVal8(Long n) { val8 = n; }

}


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.