[求助]关于hibernate里面是用中文字段

06-05-01 dihin
在做继承映射http://java.mblogger.cn/javamxj/posts/14034.aspx这个例子的时候

控制台消息如下:

Hibernate: insert into Vehicle (name, id) values (?, ?)

Hibernate: insert into Car (载客, id) values (?, ?)

Hibernate: insert into Vehicle (name, id) values (?, ?)

Hibernate: insert into Truck (载重, id) values (?, ?)

插入表都是可以的成功的

但是在读取的时候就出现问题了

具体的代码是这样的 字段里面有中文的载客,载重

sess = sf.openSession();

tx = null;

try {

tx = sess.beginTransaction();

List pets = sess.find("from " + Vehicle.class.getName());

for (Iterator it = pets.iterator(); it.hasNext();) {

Vehicle vehicle = (Vehicle) it.next();

System.out.println("车型 " + vehicle.getName()

+ " its class is: " + vehicle.getClass().getName());

}

tx.commit();

Hibernate: select vehicle0_.id as id, case when vehicle0__1_.id is not null then 1 when vehicle0__2_.id is not null then 2 when vehicle0_.id is not null then 0 end as clazz_, vehicle0_.name as name0_, vehicle0__1_.载重 as 载重1_, vehicle0__2_.载客 as 载客2_ from Vehicle vehicle0_ left outer join Truck vehicle0__1_ on vehicle0_.id=vehicle0__1_.id left outer join Car vehicle0__2_ on vehicle0_.id=vehicle0__2_.id

(这条语句我在mysql里面执行可以返回正确结果)

在hibernate里面执行就出现下面错误:

net.sf.hibernate.exception.GenericJDBCException: Could not execute query

at net.sf.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:90)

at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:79)

at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)

at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4131)

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1557)

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1531)

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1523)

at dihin.inheritance.two.Demo.<init>(Demo.java:57)

at dihin.inheritance.two.Demo.main(Demo.java:16)

Caused by: java.sql.SQLException: Column '载客2_' not found.

at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:950)

at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5015)

at net.sf.hibernate.type.StringType.get(StringType.java:18)

at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)

at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)

at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:67)

at net.sf.hibernate.loader.Loader.hydrate(Loader.java:690)

at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:631)

at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:590)

at net.sf.hibernate.loader.Loader.getRow(Loader.java:505)

at net.sf.hibernate.loader.Loader.getRowFromResultSet(Loader.java:218)

at net.sf.hibernate.loader.Loader.doQuery(Loader.java:285)

at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:138)

at net.sf.hibernate.loader.Loader.doList(Loader.java:1063)

at net.sf.hibernate.loader.Loader.list(Loader.java:1054)

at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)

at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1554)

... 4 more

帮我解决一下 谢谢了

猜你喜欢