Hibernate单向one-to-one关联查询 - provided id of the wrong type for class

---------------------Table设定信息-----------------------
Table --- Car

carId -- number -- pk 序列号
brandId -- varchar2 - fk 汽车品牌

Table --- CarBrand

brandId -- varchar2 -- pk 品牌ID
brandName -- varchar2 品牌名称

----------------------Hbm设定信息---------------------------
Car.hbm

 <id name="carId">
    <generator class="sequence">s_car_id</generator>
 </id>

 <one-to-one name="brand" class="CarBrand.class" />

CarBrand.hbm

 <id name="brandId">
   <generator class="assigned"/>
 </id>

 <property name="brandName" type="java.lang.String" column="brandName"/>

---------------------查询所有品牌为A的车辆---------------------
Criteria c = session.createCriteria();
c.createAlias(Car.class, "car");
c.createAlias("car.brand","brand");
c.add(Restriction.eq("brand.brandId","A"));'
c.list();

执行过程中产生如下报错信息
org.hibernate.TypeMismatchException: Provided id of the wrong type for class com.lw.domiane.Car Expected: class java.lang.String , got class java.lang.Long

at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:109)

at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)

at org.hibernate.impl.SessionImpl.get(SessionImpl.java:842)

at org.hibernate.impl.SessionImpl.get(SessionImpl.java:835)

at com.lw.service.imp.BaseService.findById(BaseService.java:55)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)

at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)

at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)

at $Proxy12.findById(Unknown Source)

at com.lw.web.action.CarAction.download()(CarAction.java:51)

以上我出现的状况,有谁能帮忙解决一下,谢谢!

看来没人能回答我的问题,研究了一下,终于解决了,这里分享给大家。
首先大家可以从我的表的设定看出来,brandId是一个外键,关联到carBrand表里面的brandId,我现在希望使用one-to-one的映射模式使得Car.class的类中能够产生一个Brand的对象;
有两种映射模式,主键关联模式以及唯一外键模式
主键关联就是我们正常情况下使用的

 <one-to-one name="brand" class="CarBrand.class" />

这种情况下产生的sql的形式如下:
select * from car c, carBrand cb where c.carId = cb.brandId ;

这就是我使用上面的方式报错的原因;

唯一外键模式,hbm格式如下

<many-to-one name="brand" class="CarBrand.class" unique="true" column="brandId"/>

此模式下产生sql如下
select * from car c, carBrand cb where c.barndId = cb.brandId

将Car.hbm文件中配置修改掉就可以解决这个问题了,希望对大家有帮助。

http://blog.csdn.net/itmyhome1990/article/details/7463419