请大侠帮忙看看:
.hbm文件
<hibernate-mapping>
    <class name="cn.com.lenovo.role.bean.TUserInfo" table="T_USER_INFO" schema="LENOVO">
        <id name="userId">
            <column name="USER_ID" />
            <generator class="sequence">   
                <param name="sequence">SEQ_USER_ID</param>   
            </generator>  
        </id>
        <property name="userName" type="java.lang.String">
            <column name="USER_NAME" length="60" not-null="true" />
        </property>
        <property name="userLoginName" type="java.lang.String">
            <column name="USER_LOGIN_NAME" length="60" not-null="true" />
        </property>
        <property name="userNote" type="java.lang.String">
            <column name="USER_NOTE" length="150" />
        </property>
        <property name="userPhone" type="java.math.BigDecimal">
            <column name="USER_PHONE" precision="22" scale="0" />
        </property>
        <set name="TUserRoles"
              table="t_user_role"
             cascade="save-update">             
              <key column="USER_ID"/>
              <many-to-many class="cn.com.lenovo.role.bean.TUserInfo"
                            column="ROLE_ID"/>
        </set>
    </class>
</hibernate-mapping>
测试文件:
TUserInfo user = new TUserInfo();
user.setUserName(new String("张三"));
user.setUserLoginName(new String("zhangsan"));ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext.xml");
TUserInfoDAO userService = (TUserInfoDAO) ctx.getBean("TUserInfoDAO");
userService.save(user);
oracle数据库:
create table T_USER_INFO
(
  USER_ID         NUMBER not null,
  USER_NAME       VARCHAR2(60) not null,
  USER_LOGIN_NAME VARCHAR2(60) not null,
  USER_NOTE       VARCHAR2(150),
  USER_PHONE      NUMBER
)alter table T_USER_INFO
  add constraint USER_ID_PK primary key (USER_ID)
  using index 
  tablespace USERS
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
create sequence SEQ_USER_ID
minvalue 1
maxvalue 999999999999999999999999999
start with 21
increment by 1
cache 20;

解决方案 »

  1.   

    有什么需要注意得吗?只是这样简单配置了一下!
    <property name="mappingResources">
    <list>
    <value>cn/com/lenovo/role/bean/TUserInfo.hbm.xml</value>
    </list>
    </property>
    <bean id="TUserInfoDAO"
    class="cn.com.lenovo.role.dao.TUserInfoDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    dao是自动生成的!会有什么问题??