Hibernate无法映射MySQL varchar(255)

时间:2017-05-13 03:31:43

标签: mysql hibernate jpa hibernate-mapping

如何定义此列?我试过了:

    //@Column(name="GLN_NM", nullable=false, length=255)
    //@Column(name="GLN_NM", nullable=false)
    //@Column(name="GLN_NM", nullable=false, columnDefinition="varchar(255)")
    //@Column(name="GLN_NM", nullable=false, type="text")
    //@Column(name="GLN_NM", nullable=false, columnDefinition="text")
    //@Column(name="GLN_NM", nullable=false, columnDefinition="TextType")
    @Column(name="GLN_NM", length=255)
    private String glnNm;

我看到的问题是由以下原因引起的:org.hibernate.tool.schema.spi.SchemaManagementException:  模式验证:表[gs1_gpc]中的列[GPC_NM]中遇到错误的列类型;找到[text(Types#LONGVARCHAR)],但期待[longtext(Types#CLOB)]

软件堆栈 * MySQL 5.7.17 * mysql-connector-java-5.1.41 * sbt 0.13.15 * hibernate-core-5.2.10.Final * hibernate-jpa-2.1-api-1.0.0.Final * hibernate-entitymanager-5.2.10.Final * hibernate-validator:5.2.4.Final * hibernate-commons-annotations-5.0.1.Final.jar

我已阅读https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html和几篇文章: 620778816641758408843062858831126774193386809612398597835566912672764100435561262174

打开产品数据(http://www.product-open-data.com/download/)将表定义为:

"Field"         "Type"      "Null"  "Key"   "Default"
"GCP_CD"    "varchar(13)"   "NO"    "PRI"   \N
"GLN_CD"    "varchar(13)"   "NO"    ""  \N
"GLN_NM"    "varchar(255)"  "NO"    ""  \N
"GLN_ADDR_02"   "varchar(38)"   "NO"    ""  \N
"GLN_ADDR_03"   "varchar(38)"   "NO"    ""  \N
"GLN_ADDR_04"   "varchar(38)"   "NO"    ""  \N
"GLN_ADDR_POSTALCODE" "varchar(38)" "NO" "" \N
"GLN_ADDR_CITY" "varchar(38)"   "NO"    ""  \N
"GLN_COUNTRY_ISO_CD" "varchar(38)" "NO" ""  \N
"CONTACT_NAME"  "varchar(38)"   "NO"    ""  \N
"CONTACT_TEL"   "varchar(255)"  "NO"    ""  \N
"CONTACT_HOTLINE" "varchar(255)" "YES"  ""  \N
"CONTACT_FAX"   "varchar(255)"  "NO"    ""  \N
"CONTACT_MAIL"  "varchar(255)"  "NO"    ""  \N
"CONTACT_WEB"   "varchar(255)"  "NO"    ""  \N
"GLN_LAST_CHANGE" "varchar(10)" "NO"    ""  \N
"GLN_PROVIDER"  "varchar(13)"   "NO"    ""  \N
"SEARCH_GTIN_CD" "varchar(13)"  "NO"    ""  \N
"GEPIR_GCP_CD"  "varchar(13)"   "NO"    ""  \N
"ADD_PARTY_ID"  "varchar(13)"   "NO"    ""  \N
"RETURN_CODE"   "varchar(3)"    "NO"    ""  \N
"SOURCE"    "varchar(100)"  "NO"    ""  \N
"SYNC_DT"   "date"  "YES"   ""  \N

提前致谢。

2 个答案:

答案 0 :(得分:0)

没有必要指定columnDefinition,如columnDefinition =" text"在你的pojo。

而只是放入你的pojo: @Column(名称=" GLN_NM&#34)  private String glnNm;

在你的mysql中将该列定义为: varchar(256)或LongText或MediumText根据您的要求。

答案 1 :(得分:0)

正如上面的评论所述,GLN_NM列工作得很好。麻烦制造者是GPC_NM列(未包含在OP原始代码中)