我正在使用Hibernate 4.3创建POJO类并从Sql Server表映射文件。但它创造了所有的“nvarchar”#39;字段到' Serializable'。我希望他们成为' String'类型。
在我提到的reveng.xml文件中 -
<type-mapping>
<sql-type jdbc-type="NVARCHAR" hibernate-type="string" />
<sql-type jdbc-type="VARCHAR" hibernate-type="string" />
</type-mapping>
但没有帮助。
我的逆向工程文件是 -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-catalog="Copy_Up-Tourism" match-schema="dbo"/>
<type-mapping>
<sql-type jdbc-type="NVARCHAR" hibernate-type="string" />
<sql-type jdbc-type="VARCHAR" hibernate-type="string" />
</type-mapping>
<table-filter match-name="Contents"/>
<table-filter match-name="CategoryDatas"/>
<table-filter match-name="TileExperience"/>
<table-filter match-name="PushTypes"/>
<table-filter match-name="DestinationDatas"/>
<table-filter match-name="PlaceDatas"/>
<table-filter match-name="EventDatas"/>
<table-filter match-name="YoutubeVideoTag"/>
<table-filter match-name="PushManagers"/>
<table-filter match-name="Activities"/>
<table-filter match-name="Languages"/>
<table-filter match-name="Categories"/>
</hibernate-reverse-engineering>
我尝试了许多解决方案,例如Link,但没有帮助。请帮忙
答案 0 :(得分:2)
请执行以下操作:
改变这个:
<sql-type jdbc-type="NVARCHAR" hibernate-type="string" />
对此:
<sql-type jdbc-type="NVARCHAR" hibernate-type="java.lang.String" />
添加 jdbc.properties 文件:
oracle
:
hibernatetool.metadatadialect=org.hibernate.cfg.reveng.dialect.OracleMetaDataDialect
对于其他人:
H2MetaDataDialect
dialect用于解决H2数据库中的调整问题
JDBCMetaDataDialect
使用标准JDBC读取元数据的方言
MySQLMetaDataDialect
方言
然后像往常一样执行:
答案 1 :(得分:0)
我的尊敬文件就像
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<type-mapping>
<sql-type jdbc-type="NVARCHAR" hibernate-type="string" />
</type-mapping>
<table-filter match-name="TempTable"/>
</hibernate-reverse-engineering>
创建了POJO
public class TempTable implements java.io.Serializable {
private int tempId;
private String data;
public TempTable() {
}
public TempTable(int tempId) {
this.tempId = tempId;
}
public TempTable(String data) {
this.data = data;
}
public int getTempId() {
return this.tempId;
}
public void setTempId(int tempId) {
this.tempId = tempId;
}
public String getData() {
return this.data;
}
public void setData(String data) {
this.data = data;
}
}
结论只需添加
<type-mapping>
<sql-type jdbc-type="NVARCHAR" hibernate-type="string" />
</type-mapping>
要尊重档案:)