Hi all,I use hibernate tools to create classes to store my db tables.I have a problem with strings. I need to trim values but I want to doit without to touch the automatically generated code...What can I do?Thanks all,DM
|
|
1
|
|
|
|
Reply
|
diemme29 (9)
|
3/29/2007 11:12:06 AM |
|
On 29.03.2007 13:12, DM wrote:> I use hibernate tools to create classes to store my db tables.> I have a problem with strings. I need to trim values but I want to do> it without to touch the automatically generated code...> What can I do?This is something you should do in application land, i.e. in your Java classes. Hibernate just transfers data from the application to the DB.Kind regards robert
|
|
0
|
|
|
|
Reply
|
Robert
|
3/29/2007 11:15:19 AM
|
|
On 29 Mar, 13:15, Robert Klemme <shortcut...@googlemail.com> wrote:> On 29.03.2007 13:12, DM wrote:>> > I use hibernate tools to create classes to store my db tables.> > I have a problem with strings. I need to trim values but I want to do> > it without to touch the automatically generated code...> > What can I do?>> This is something you should do in application land, i.e. in your Java> classes. Hibernate just transfers data from the application to the DB.>> Kind regards>> robertI try to explain.I load a table on a HashMap (the key of the table = the key of themap) then I want to get the value from the map given the key.The problem is the key in the db is i.e. "LOG " (the stringis filled with spaces...).If I call map.get("LOG") I don't found nothing... I've to callmap.get("LOG "). This disturbs me...I've inserted a .trim() on the constructor of the generated class, butI wish to obtain the same result without touch it...I've to wrap the generated class or can I use a different method?Thanks,DM
|
|
0
|
|
|
|
Reply
|
DM
|
3/29/2007 12:09:05 PM
|
|
DM wrote:> On 29 Mar, 13:15, Robert Klemme <shortcut...@googlemail.com> wrote:>> On 29.03.2007 13:12, DM wrote:>>>>> I use hibernate tools to create classes to store my db tables.>>> I have a problem with strings. I need to trim values but I want to do>>> it without to touch the automatically generated code...>>> What can I do?>> This is something you should do in application land, i.e. in your Java>> classes. Hibernate just transfers data from the application to the DB.>>>> Kind regards>>>> robert> > I try to explain.> I load a table on a HashMap (the key of the table = the key of the> map) then I want to get the value from the map given the key.> The problem is the key in the db is i.e. "LOG " (the string> is filled with spaces...).> If I call map.get("LOG") I don't found nothing... I've to call> map.get("LOG "). This disturbs me...> I've inserted a .trim() on the constructor of the generated class, but> I wish to obtain the same result without touch it...> > I've to wrap the generated class or can I use a different method?If you can change the data model implementation, consider using VARCHAR instead of CHAR for those columns.-- Lew
|
|
0
|
|
|
|
Reply
|
Lew
|
3/29/2007 12:25:52 PM
|
|
On 29.03.2007 14:25, Lew wrote:> DM wrote:>> On 29 Mar, 13:15, Robert Klemme <shortcut...@googlemail.com> wrote:>>> On 29.03.2007 13:12, DM wrote:>>>>>>> I use hibernate tools to create classes to store my db tables.>>>> I have a problem with strings. I need to trim values but I want to do>>>> it without to touch the automatically generated code...>>>> What can I do?>>> This is something you should do in application land, i.e. in your Java>>> classes. Hibernate just transfers data from the application to the DB.>>>>>> Kind regards>>>>>> robert>>>> I try to explain.>> I load a table on a HashMap (the key of the table = the key of the>> map) then I want to get the value from the map given the key.>> The problem is the key in the db is i.e. "LOG " (the string>> is filled with spaces...).>> If I call map.get("LOG") I don't found nothing... I've to call>> map.get("LOG "). This disturbs me...>> I've inserted a .trim() on the constructor of the generated class, but>> I wish to obtain the same result without touch it...>>>> I've to wrap the generated class or can I use a different method?> > If you can change the data model implementation, consider using VARCHAR > instead of CHAR for those columns.Yeah, change the data in the DB. Or, if access is read only, create a DB view that does the trimming and use that instead of the table. robert
|
|
0
|
|
|
|
Reply
|
Robert
|
3/29/2007 1:43:25 PM
|
|
On 29 Mar, 15:43, Robert Klemme <shortcut...@googlemail.com> wrote:> On 29.03.2007 14:25, Lew wrote:>>>> > DM wrote:> >> On 29 Mar, 13:15, Robert Klemme <shortcut...@googlemail.com> wrote:> >>> On 29.03.2007 13:12, DM wrote:>> >>>> I use hibernate tools to create classes to store my db tables.> >>>> I have a problem with strings. I need to trim values but I want to do> >>>> it without to touch the automatically generated code...> >>>> What can I do?> >>> This is something you should do in application land, i.e. in your Java> >>> classes. Hibernate just transfers data from the application to the DB.>> >>> Kind regards>> >>> robert>> >> I try to explain.> >> I load a table on a HashMap (the key of the table = the key of the> >> map) then I want to get the value from the map given the key.> >> The problem is the key in the db is i.e. "LOG " (the string> >> is filled with spaces...).> >> If I call map.get("LOG") I don't found nothing... I've to call> >> map.get("LOG "). This disturbs me...> >> I've inserted a .trim() on the constructor of the generated class, but> >> I wish to obtain the same result without touch it...>> >> I've to wrap the generated class or can I use a different method?>> > If you can change the data model implementation, consider using VARCHAR> > instead of CHAR for those columns.>> Yeah, change the data in the DB. Or, if access is read only, create a> DB view that does the trimming and use that instead of the table.>> robertI work on a big project on a db with more than 40 tables anddistributed on many clients... changing the db is not a solution.The best solution right now is to wrap java String in TrimString andusing this class instead of Strings... but the "tablename.hbm.xml"file is automatically generated mapping db "char" into java String.Can I map automatically "char" into TrimString?Thanks,DM
|
|
0
|
|
|
|
Reply
|
DM
|
3/29/2007 2:00:30 PM
|
|
On 29.03.2007 16:00, DM wrote:
> On 29 Mar, 15:43, Robert Klemme <shortcut...@googlemail.com> wrote:
>> On 29.03.2007 14:25, Lew wrote:
>>
>>
>>
>>> DM wrote:
>>>> On 29 Mar, 13:15, Robert Klemme <shortcut...@googlemail.com> wrote:
>>>>> On 29.03.2007 13:12, DM wrote:
>>>>>> I use hibernate tools to create classes to store my db tables.
>>>>>> I have a problem with strings. I need to trim values but I want to do
>>>>>> it without to touch the automatically generated code...
>>>>>> What can I do?
>>>>> This is something you should do in application land, i.e. in your Java
>>>>> classes. Hibernate just transfers data from the application to the DB.
>>>>> Kind regards
>>>>> robert
>>>> I try to explain.
>>>> I load a table on a HashMap (the key of the table = the key of the
>>>> map) then I want to get the value from the map given the key.
>>>> The problem is the key in the db is i.e. "LOG " (the string
>>>> is filled with spaces...).
>>>> If I call map.get("LOG") I don't found nothing... I've to call
>>>> map.get("LOG "). This disturbs me...
>>>> I've inserted a .trim() on the constructor of the generated class, but
>>>> I wish to obtain the same result without touch it...
>>>> I've to wrap the generated class or can I use a different method?
>>> If you can change the data model implementation, consider using VARCHAR
>>> instead of CHAR for those columns.
>> Yeah, change the data in the DB. Or, if access is read only, create a
>> DB view that does the trimming and use that instead of the table.
>>
>> robert
>
> I work on a big project on a db with more than 40 tables and
> distributed on many clients... changing the db is not a solution.
Adding a view doesn't really hurt.
> The best solution right now is to wrap java String in TrimString and
> using this class instead of Strings... but the "tablename.hbm.xml"
> file is automatically generated mapping db "char" into java String.
> Can I map automatically "char" into TrimString?
Maybe. You would have to hack hibernate or dialects I presume.
Regards
robert
|
|
0
|
|
|
|
Reply
|
Robert
|
3/29/2007 2:48:54 PM
|
|
On 29 Mar, 16:48, Robert Klemme <shortcut...@googlemail.com> wrote:
> On 29.03.2007 16:00, DM wrote:
>
>
>
> > On 29 Mar, 15:43, Robert Klemme <shortcut...@googlemail.com> wrote:
> >> On 29.03.2007 14:25, Lew wrote:
>
> >>> DM wrote:
> >>>> On 29 Mar, 13:15, Robert Klemme <shortcut...@googlemail.com> wrote:
> >>>>> On 29.03.2007 13:12, DM wrote:
> >>>>>> I use hibernate tools to create classes to store my db tables.
> >>>>>> I have a problem with strings. I need to trim values but I want to do
> >>>>>> it without to touch the automatically generated code...
> >>>>>> What can I do?
> >>>>> This is something you should do in application land, i.e. in your Java
> >>>>> classes. Hibernate just transfers data from the application to the DB.
> >>>>> Kind regards
> >>>>> robert
> >>>> I try to explain.
> >>>> I load a table on a HashMap (the key of the table = the key of the
> >>>> map) then I want to get the value from the map given the key.
> >>>> The problem is the key in the db is i.e. "LOG " (the string
> >>>> is filled with spaces...).
> >>>> If I call map.get("LOG") I don't found nothing... I've to call
> >>>> map.get("LOG "). This disturbs me...
> >>>> I've inserted a .trim() on the constructor of the generated class, but
> >>>> I wish to obtain the same result without touch it...
> >>>> I've to wrap the generated class or can I use a different method?
> >>> If you can change the data model implementation, consider using VARCHAR
> >>> instead of CHAR for those columns.
> >> Yeah, change the data in the DB. Or, if access is read only, create a
> >> DB view that does the trimming and use that instead of the table.
>
> >> robert
>
> > I work on a big project on a db with more than 40 tables and
> > distributed on many clients... changing the db is not a solution.
>
> Adding a view doesn't really hurt.
>
> > The best solution right now is to wrap java String in TrimString and
> > using this class instead of Strings... but the "tablename.hbm.xml"
> > file is automatically generated mapping db "char" into java String.
> > Can I map automatically "char" into TrimString?
>
> Maybe. You would have to hack hibernate or dialects I presume.
>
> Regards
>
> robert
I've found... on hibernate.org / Hibernate Users Faq / Tips and Tricks
How can I trim spaces from String data persisted to a CHAR column?
Use a UserType.
....doh... :-)
DM
|
|
0
|
|
|
|
Reply
|
DM
|
3/29/2007 3:22:38 PM
|
|
|
7 Replies
555 Views
(page loaded in 0.129 seconds)
Similiar Articles: nawk: out of space in tostring on ... - comp.lang.awkEven if the problem does not occur with gawk, I still cannot use it. ... function trim(string) { sub(/^[ \t]+/, "", string); sub(/[ \t]+$/, "", string ... To combine string and integer in F90 - comp.lang.fortran ...> Possibly it could be a problem for the OP if the numeric string were > less than 100 > and blanks ... oldstr =3D 'str' n =3D 123 write(newstr, '(A,I0)') trim ... Difference between commit and flush in Hibernate - comp.lang.java ...I read the book "Java Persistence with hibernate" which ... List<T> findByExample(T exampleInstance, String ... Simple code encryption (xor) problem - comp.lang.asm.x86 ... how to check extension of an image file - comp.soft-sys.matlab ...fileparts() and do string comparison on the extension ... so that I can display it on a jpanel.Problem is that ... out one thing. ... a good time for me to get some sleep ... Easiest way to search a list of String in a field? - comp.soft-sys ...... dataset A2 is transaction level data, there is 1 string ... want to know how do you usually solve this kind of problem? ... select * , index (upcase(transactions.X), trim ... Something bad happened to my gfortran installation - comp.lang ...This problem only seems to be happening in 32-bit gfortran; I'm not sure whether ... save write(string,'(a,i0)') 'Depth is ',depth write(*,'(a)') trim(string ... Trim file with sed - comp.unix.programmer... Any code in this post is released | A Problem-Solution ... line that I can execute: cat file_old.txt | sed 's/string ... The Trim function ONLY removes leading / trailing space ... Grep string with spaces - comp.unix.shellI'm having a problem with a grep now. I'm using this code ... comp.lang.awk FindBetween: A Useful GREP String ... Remove surrounding quotes via FOR command. Trim Right ... Floating Point and printf() - comp.lang.asm.x86... silly statement concerning MASM, not the original problem ... comp.lang.asm.x86 new xgawk time functions (sleep and ... GENERAL: PRECISION OF PRINTF %F FORMAT STRING SYMPTOMS: I ... getgenbank problem - comp.soft-sys.matlabgetgenbank problem Follow ... you can even automate the search by creating the accession number string and then ... Hibernate and String trim problem - Velocity Reviews - Computer ...Hi all, I use hibernate tools to create classes to store my db tables. I have a problem with strings. I need to trim values but I want to do it without to touch the Hibernate Community • View topic - Trim string typePost subject: Trim string type ... to help with Windows Forms DataBinding and the problems ... JBoss and Hibernate are registered trademarks and ... 7/24/2012 4:07:22 AM
|