-->
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.  [ 7 posts ] 
Author Message
 Post subject: PostgreSQL, VARCHAR, and length
PostPosted: Fri Sep 17, 2004 6:31 am 
Newbie

Joined: Fri Sep 17, 2004 6:24 am
Posts: 4
Just a quick question;

I have a String property that I have written the XDoclet tags for:

Code:
  /**
   * @hibernate.property update="false"
   *                     insert="false"
   */
  public String getChr()
  {
    return chr;
  }


This generates:

Code:
        <property
            name="chr"
            type="java.lang.String"
            update="false"
            insert="false"
            access="property"
            column="chr"
        />


which in turn generates:

Code:
    Column     |          Type          | Modifiers
---------------+------------------------+-----------
chr           | character varying(255) |


My question is; How can I get rid of the 255? With PostgreSQL, you can define a VARCHAR record without any length, so that it expands to whatever size you need...

I know I can add a LENGTH property to my XDoclet tag, but that would just allow me to set it to a really high number (which I am not sure is a good idea, as I don't know if Postgres will allocate that memory per row whether it needs it or not)

Is declaring the type to be "java.sql.Clob" my only other option?

Thanks for your time, and sorry if this is a regualr (and boring question)... I did a search, but couldn't find anything...

Bloid.


Top
 Profile  
 
 Post subject: Did you find any answer to this
PostPosted: Fri Oct 01, 2004 6:14 am 
Newbie

Joined: Tue Jul 20, 2004 7:03 am
Posts: 19
Location: Spain
Hi, i'm on the same spot.

Any conclusion?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 6:31 am 
Newbie

Joined: Fri Sep 17, 2004 6:24 am
Posts: 4
The best I could come up with, is to define the field as:

Code:
  /**
   * @hibernate.property update="false"
   *                     insert="false"
   *                     type="java.sql.Clob"
   */


Which makes Hibernate generate it as a "TEXT" field (apparently there is no performance with using a field of type TEXT over a VARCHAR)

:-)

It would be nice to know how to remove the "length" bit though...

Tim


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 7:02 am 
Newbie

Joined: Tue Jul 20, 2004 7:03 am
Posts: 19
Location: Spain
I've found a 'feature' here

[url]http://cephas.net/blog/2004/06/29/hibernate_ddl_export_and_sql_length.html
[/url]

But i'm not using xdoclet yet. :(

I will try your TEXT solution, thans.


Top
 Profile  
 
 Post subject: Solution
PostPosted: Fri Oct 01, 2004 7:12 am 
Newbie

Joined: Tue Jul 20, 2004 7:03 am
Posts: 19
Location: Spain
Easier than that !!

If you want a transparent long string type, only use this in your mapping:

Code:
<element column="mega_long_string_of_the_dead" type="text" />


Thanks for the answer, pal.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 7:14 am 
Newbie

Joined: Fri Sep 17, 2004 6:24 am
Posts: 4
Cool :-) That would solve it (but as that guy says, VARCHAR in SQL Server defaults to length "1", so would break the code if it was moved to another db)

Nice find though :-)

I'm guessing it is a problem with the postgres-dialect that it should know that if length is not specified, then it doesn't need to default to 255 with postgres, as postgres can handle varchar length dynamically with no performance hit

:-)

Good luck with it!!

Tim


Top
 Profile  
 
 Post subject: Re: Solution
PostPosted: Fri Oct 01, 2004 7:21 am 
Newbie

Joined: Fri Sep 17, 2004 6:24 am
Posts: 4
steinkel wrote:
Easier than that !!

If you want a transparent long string type, only use this in your mapping:

Code:
<element column="mega_long_string_of_the_dead" type="text" />


Thanks for the answer, pal.


Ahhh, yeah, but to generate the "type=text" bit using XDoclet, I believe you have to define the type as CLOB in the java file (as I did)..

That generates the mapping to "text" :-)

Glad we could help each other out!

Good luck with it :-)

Tim


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