请哪位高手帮忙看看,困扰我好久了!!
测试代码:
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);
.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>
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;
测试代码:
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);
.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>
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;
<generator class="sequence">
<param name="sequence">SEQ_USER_ID </param>
</generator> 换成 <generator class="identity">
</generator>
谁说Oracle不支持自增 序列不也是自增吗
并且楼主的序列Id也配的差不多啊
应该不是这个问题 楼主还是自己检查一下其他方面的问题
看一看applicationContext.xml这个文件配置有错没有
<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是自动生成的!会有什么问题??