How to set hibernate-mapping to strings longer than 255 characters?

So, I'm trying to learn by creating a blog engine. I am using Hibernate with MySQL. Here is my hibernate-mapping for the "Post" class:

<hibernate-mapping package="com.enw.blog"> <class name="Post" table="POST"> <id name="id" column="POST_ID"> <generator class="native"/> </id> <property name="title"/> <property name="text"/> <property name="date" type="timestamp" column="POST_DATE"/> </class> </hibernate-mapping> 

Of course, the message can be long. By default, this sets up a table with rows represented as VARCHAR(255) . How to change this?

I also appreciate the pointer to the right place in the documents, I can not move them effectively.

+7
java mysql hibernate
source share
2 answers

length should do the job!

 <property name="title" length="1234"/> 

See Chapter 5. Basic O / R mapping: property

+4
source share

You can do this with annotations.

 @Column(length=256) 

or xml

 <property name="name" type="java.lang.String"> <column name="COLUMN" length="256"/> </property> 

Another thing, you can also change sql-type if you want to use a specific type.

Sources:

Related topics:

  • Hibernate UserType and specific length
+5
source share

All Articles