个人网站:www.longhuiwang.com
SSH案例下载地址:http://download.csdn.net/detail/xiangqian0505/3886417(SSH案例是oracle+ssh。)
hibernate获取序列的问题:
hibernate连接oracle有两种方式,一种是制定sequence的名字 如:
<id name="userid" type="java.lang.Long">
??????????? <column name="USERID" precision="18" scale="0" />
??????????? <generator class="sequence" >
??????????? <param name="sequence">SEQ_USER_PROPER</param>
??????????? </generator>
??????? </id>
注意SEQ_USER_PROPER是序列名称
如果要使用native,则必须创建名为HIBERNATE_SEQUENCE 的sequence
? -- Create sequence
create sequence HIBERNATE_SEQUENCE
minvalue 1
maxvalue 9999999999
start with 21
increment by 1
cache 20;
第二种方式:
< id name="id" column="ID">
< generator class="native" />
< /id>
?
Struts配置文件注意的问题:
特别要注意的是:message-resources放在plug-in插件之前。
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/> <message-resources parameter="com.temp.struts.ApplicationResources" /> <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/> </plug-in>
?
?
spring映射时property的name属性必须和要映射的bean的id匹配。
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="datasouce" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9Dialect </prop> </props> </property> <property name="mappingResources"> <list> <value>com/temp/vo/UserProper.hbm.xml</value></list> </property></bean> <bean id="userProperDAO" class="com.temp.dao.UserProperDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean>
?
?
?
附件中ssh项目中数据库的用户名是testssh
?
创建表:
-- Create table
create table USER_PROPER
(
? USERID?? NUMBER(18) not null,
? USERNAME VARCHAR2(60),
? USERPASS VARCHAR2(20),
? EMAIL??? VARCHAR2(50)
)
tablespace LCBIKE
? pctfree 10
? initrans 1
? maxtrans 255
? storage
? (
??? initial 64K
??? minextents 1
??? maxextents unlimited
? );
-- Add comments to the table
comment on table USER_PROPER
? is '用户信息表';
-- Create/Recreate primary, unique and foreign key constraints
alter table USER_PROPER
? add constraint PKUSER primary key (USERID)
? using index
? tablespace LCBIKE
? pctfree 10
? initrans 2
? maxtrans 255
? storage
? (
??? initial 64K
??? minextents 1
??? maxextents unlimited
? );
创建表序列:
-- Create sequence
create sequence SEQ_USER_PROPER
minvalue 1
maxvalue 9999999999
start with 21
increment by 1
cache 20;
?
#将日志信息生成日志文件
#log4j.rootLogger=info,A1 #log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender #log4j.appender.A1.Append=true #log4j.appender.A1.File=D:/log4j.log #log4j.appender.A1.DatePattern = '.'yyyy-MM-dd'.log' #log4j.appender.A1.layout=org.apache.log4j.PatternLayout #log4j.appender.A1.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss} Method: %l%n%m%n
#打印输出到tomcat控制台信息配置 log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n log4j.rootLogger=info, stdout #log4j.rootLogger=warn, stdout
#详情请参见ssh附件
?
?
最后提醒大家: 根据视频配置完之后,工程中缺两个包,我为了这个问题纠结了一天。
commons-dbcp.jar
commons-pool.jar(附件)