-->
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: String right data truncation
PostPosted: Fri Jul 01, 2005 5:25 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
Hi folks,

I'd the problem that I was getting the error in the subject when I tried
to insert a string of greater length than the database table declaration.

i.e. my Response object has a statusLine string. If this string was greater
than 255 for instance I'd get the error. So I implemented an overflow table
for such strings.

Basically the constructor of the Response object splices the incoming string
into a statusLine that contains the first 255 chars and then the rest gets
put into the overflow string.

Here's the constructor.
Code:
   public void setStatusLine(String statusLine) {
        if (statusLine.length() > 255) {
            // Creates a new String instance for the substring from 0,255
            this.statusLine = new String (statusLine.substring(0, 254));
            // Creates a new String instance for the substring from 255 to the end.
            setOverflow(new Overflow(new String (statusLine.substring(254, statusLine.length()))));
        } else {
            this.statusLine = statusLine;
        }
    }


For an initial statusLine of 1000 chars, the first 255 goes to the global
statusLine object and the remainder goes into the Overflow object.

when it comes to inserting this Response object, the overflow object goes
in fine and only contains the remainder of the initial string i.e. 745 chars.


however when it comes time to insert the statusLine object the whole
string (all 1000 chars is returned from the method
Code:
Object[] values = persister.getPropertyValuesToInsert(entity, source);


in the AbstractSaveEventListener.

however debugging the Response object at that point shows that the
statusLine string encapsulated in the object only has 254 chars?

Basically there's something going on with the CGLib libraries when it goes
to retrieve the object.

Has anyone any idea how the CGLib retrieves the values for the insert?

Thanks,
Mark.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 01, 2005 5:49 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
Awwwww I'm a very silly programmer altogether.
Of course the CGLib stuff was returning the full whack...
For a laugh here's my getter method. I went to college??? Where did it
all go wrong?

Code:
    public String getStatusLine() {
        return new String(statusLine + getOverflow());
    }


Thanks,
Mark.


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.