如何设置hibernate-mapping以允许字符串超过255个字符? [英] How to set hibernate-mapping to allow for Strings longer than 255 characters?

查看:116
本文介绍了如何设置hibernate-mapping以允许字符串超过255个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图通过创建一个博客引擎来学习。我在MySQL中使用Hibernate。这是我的Post类的hibernate-mapping:

 < hibernate-mapping package =com.enw.blog > 
< class name =Posttable =POST>
< id name =idcolumn =POST_ID>
< generator class =native/>
< / id>
< property name =title/>
< property name =text/>
< property name =datetype =timestampcolumn =POST_DATE/>
< / class>
< / hibernate-mapping>

当然,一篇文章可能会很长。默认情况下,这会设置一个表,其中的字符串表示为 VARCHAR(255)。我怎么改变它?



我也很欣赏指向文档中正确位置的指针,我似乎无法有效地导航它们。

解决方案

length 应该完成这项工作!

 < property name =titlelength =1234/> 

请参阅第5章基本O / R映射:属性


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">
       <generator 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.

解决方案

length should do the job!

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

See Chapter 5. Basic O/R Mapping: Property

这篇关于如何设置hibernate-mapping以允许字符串超过255个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆