Member Menu
 
 Monthly JBoss newsletter:
 
Java Persistence with Hibernate
CaveatEmptor

Long Strings/CLOB/TEXT for MySQL

private String comments;
  
/**
 * @hibernate.property column="comments" length="2147483647"
 **/

public String getComments() {
    return comments;
}

XDoclet will generate this is the .hbm.xml file:

<property
    name="comments"
    type="java.lang.String"
    update="true"
    insert="true"
    length="2147483647"
    />

Creates a LongText column in the table for 'blurb'. (LongText holds up to 2,147,483,647 characters).


  NEW COMMENT

Alternative: use the "text" type (Hibernate 2.1+) 21 Nov 2003, 16:11 brenuart
With Hibernate 2.1-* you can use the following mapping strategy:

   <property name="name" type="text" />

It will map your string to a TEXT column if supported (it is for 
MySQL) or CLOB... (cfr. Reference doc, 4.2.2. Basic value types)
 
Concerning previous comment... 05 Mar 2007, 05:38 cblin
You still have to do <propert name="whatever" type="text" length="X" />

with X = 2147483647 if you want a longtext (i.e 2^32 / 2 -1 because the
hibernate parser expect a integer) and 16777215 (2^24 - 1) if you want a
mediumtext

see also www.hibernate.org/56.html
 
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]