Could not determine type for: String

初学hibernate,遇到这样一个问题。搞了半天都不知道问题出在哪儿,结果发现是配置文件中的类型写法出了问题。

Exception in thread "main" java.lang.ExceptionInInitializerError
at hib.HibernateUtil.<clinit>(HibernateUtil.java:21)
at hib.dynamicmodel.DynamicDemo.main(DynamicDemo.java:24)
Caused by: org.hibernate.MappingException: Could not determine type for: String, for columns: [org.hibernate.mapping.Column(name)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)



  <property name = "name" column="name" type = "string"/>


开始我写的是 type = "String",正确的因该是上面的,type = "string"
type指的是hibernate中的类型,不是java中的String类型,必须小写。

下面是Java类型,hibernate类型 sql类型对照表:



Hibernate映射类型对照表
java类型
Hibernate映射类型 SQL类型java.math.BigDecimal big_decimal numericbyte[] binary varbinary(blob)boolean(java.lang.Boolean) boolean bitbyte(java.lang.Byte) byte tinyintjava.util.Calendar calendar timestampjava.sql.Clob clob clobjava.util.Date 或java.sql.Date date datedouble(java.lang.Double) double doublefloat(java.lang.Float) float floatint (java.lang.Integer) integer integerjava.util.Local local varcharlong(java.lang.Long) long bigintjava.io.Serializable的某个实例 serializable varbinary(或blob)java.lang.String string varcharjava.lang.String text clobjava.util.Date 或 java.sql.Timestamp time timestamp

你可能感兴趣的:(java,thread,sql,Hibernate)