开发者

How to set hibernate-mapping to allow for Strings longer than 255 characters?

开发者 https://www.devze.com 2023-01-13 16:03 出处:网络
So I\'m trying to learn by creating a blog-engine.I\'m using Hibernate with MySQL.Here is my hibernate-mapping for the \"Post\" class:

So I'm trying to learn by creating a blog-engine. I'm 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">
       <gene开发者_运维百科rator class="native"/>
     </id>
     <property name="title"/>
     <property name="text"/>
     <property name="date" type="timestamp" column="POST_DATE"/>
   </class>
 </hibernate-mapping>

Of course, a post could be long. By default this sets up a table with the Strings represented as VARCHAR(255). How do I alter this?

I'd also appreciate a pointer to the right place in the docs, I can't seem to navigate them effectively.


You can do this with either 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 the sql-type if you want to use a specific type.

Sources :

  • Hibernate forums

Related topics :

  • Hibernate UserType and a defined length


length should do the job!

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

See Chapter 5. Basic O/R Mapping: Property

0

精彩评论

暂无评论...
验证码 换一张
取 消