Hibernate存入会员实体失败

rgone 发布于 2012/06/19 18:07
阅读 709
收藏 1

小弟不是专业java开发,最近在看shopxx的源码,一个简单的会员存入,让我鼓捣了很久都没有正常存入。各位大牛帮忙看看有什么问题呢。谢谢!

Hibernate Dao接口的实现:

	@SuppressWarnings("unchecked")
	public PK save(T entity) {
		Assert.notNull(entity, "entity is required");
		System.out.println("in BaseDaoImpl!!!---------------");
		System.out.println ((PK) getSession().save(entity));
		return (PK) getSession().save(entity);
	}

Struts Action里调用service方法存入会员: 

member.setUsername(member.getUsername().toLowerCase());     
member.setPassword(DigestUtils.md5Hex(member.getPassword()));
member.setSafeQuestion(null);
member.setSafeAnswer(null);
member.setScore(0);
member.setIsAccountEnabled(true);
member.setIsAccountLocked(false);
member.setLoginFailureCount(0);
member.setLockedDate(null);
member.setRegisterIp(getRequest().getRemoteAddr());
member.setLoginIp(getRequest().getRemoteAddr());
member.setLoginDate(new Date());
member.setPasswordRecoverKey(null);
member.setMemberAttributeMap(null);
member.setReceiverSet(null);

memberService.save(member);

加载中
0
rgone
rgone
有弄ssh的帮忙看看啊...
0
yzw2048
yzw2048
报啥错?查查事务上是否配置了只读
rgone
rgone
回复 @Dong : 什么都不报,如果hibernate存入不成功应该会报一些异常或把sql语句打印出来,可是现在连sql语句都没有打印出来。是不是存入动作还没有到达hibernate呢?
yzw2048
yzw2048
回复 @饶过 : spring配置
rgone
rgone
什么都错都不爆,就是看数据库里没有存入数据。您说的“ 查查事务上是否配置了只读 ”是指定的数据库还是spring的配置呢。谢谢!
0
星星爷
星星爷
打开show_sql, 看看执行的是啥
星星爷
星星爷
看看有没有insert或update
rgone
rgone
已经配置了hibernate.show_sql=true
0
rgone
rgone

@星迷 @Dong我修改了shopxx的配置:

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:oscache="http://www.springmodules.org/schema/oscache" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springmodules.org/schema/oscache http://www.springmodules.org/schema/cache/springmodules-oscache.xsd" default-lazy-init="true">

	<!-- 设置需要进行Spring注解扫描的类包 -->
	<context:component-scan base-package="com.deng" />
	
	<!-- 数据库配置文件 -->
	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
		<property name="ignoreResourceNotFound" value="true" />
		<property name="locations">
			<list>
				<value>classpath*:/database.properties</value>
			</list>
		</property>
	</bean>
	
	<!-- 数据源配置 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
		<!-- JDBC驱动名称 -->
		<property name="driverClass" value="${jdbc.driver}" />
		<!-- JDBC连接URL -->
		<property name="jdbcUrl" value="${jdbc.url}" />
		<!-- 数据库用户名 -->
		<property name="user" value="${jdbc.username}" />
		<!-- 数据库密码 -->
		<property name="password" value="${jdbc.password}" />
		<!-- 连接池初始值 -->
		<property name="initialPoolSize" value="${pool.initialPoolSize}" />
		<!-- 连接池最小值 -->
		<property name="minPoolSize" value="${pool.minPoolSize}" />
		<!-- 连接池最大值 -->
		<property name="maxPoolSize" value="${pool.maxPoolSize}" />
		<!-- 连接池最大空闲时间 -->
		<property name="maxIdleTime" value="${pool.maxIdleTime}" />
		<!-- 当连接池中的连接耗尽时,一次性创建新连接的数量 -->
		<property name="acquireIncrement" value="${pool.acquireIncrement}" />
		<!-- 当连接池中的连接耗尽时,获取新连接的超时时间 -->
		<property name="checkoutTimeout" value="${pool.checkoutTimeout}" />
		<!-- 连接池内单个连接所拥有的最大缓存Statement数 -->
		<property name="maxIdleTimeExcessConnections" value="${pool.maxIdleTimeExcessConnections}" />
	</bean>
	
	<!-- 数据库命名策略 -->
	<bean id="databaseNamingStrategy" class="com.deng.common.DatabaseNamingStrategy">
		<!-- 数据库表名前缀 -->
		<property name="tablePrefix" value="${namingStrategy.tablePrefix}" />
		<!-- 是否以下划线形式命名 -->
		<property name="isAddUnderscores" value="${namingStrategy.isAddUnderscores}" />
		<!-- 命名最大长度限制 -->
		<property name="maxLength" value="${namingStrategy.maxLength}" />
    </bean>
	
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="entityInterceptor" ref="entityInterceptor" /> <!-- 没有此拦截器无法生成表! -->
		
		<!-- 数据库表的命名策略 -->
		<property name="namingStrategy" ref="databaseNamingStrategy" /><!-- 使用这个,不用这个将会不产生shanghu_开头的表文件!!-->
		
		<property name="hibernateProperties">
			<value>
				<!-- 数据库方言 -->
				hibernate.dialect=${hibernate.dialect}
				hibernate.show_sql=true
				hibernate.format_sql=true
				<!-- 自动创建|更新|验证数据库表结构 -->
				hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
				<!-- 是否输出SQL语句到控制台 -->
				hibernate.show_sql=${hibernate.show_sql}
				<!-- 是否格式化输出到控制台的SQL语句 -->
				hibernate.format_sql=${hibernate.format_sql}
				<!-- 是否开启二级缓存 -->
				hibernate.cache.use_second_level_cache=${hibernate.cache.use_second_level_cache}
				<!-- 二级缓存产品 -->
				hibernate.cache.provider_class=${hibernate.cache.provider_class}
				<!-- 是否开启查询缓存 -->
				hibernate.cache.use_query_cache=${hibernate.cache.use_query_cache}
				<!-- 数据库批量查询数 -->
				hibernate.jdbc.fetch_size=${hibernate.jdbc.fetch_size}
				<!-- 数据库批量更新数 -->
				hibernate.jdbc.batch_size=${hibernate.jdbc.batch_size}
			</value>
		</property>
		<property name="packagesToScan" value="com.deng.entity"/>
	</bean>
	
	<!-- 缓存配置 -->
	<oscache:config configLocation="classpath:oscache.properties" id="cacheProvider" />
	<oscache:annotations providerId="cacheProvider">
		<oscache:caching id="caching" cronExpression="0 1 * * *" refreshPeriod="3600" />
		<oscache:caching id="tempCaching" refreshPeriod="300" />
		<oscache:flushing id="flushing" />
	</oscache:annotations>
	
	<bean id="cacheManager" class="org.springmodules.cache.provider.oscache.OsCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:oscache.properties" />
    </bean>
    
    <bean id="springUtil" class="com.deng.util.SpringUtil" lazy-init="false" />
    
    <!--  
	<bean id="freemarkerManager" class="net.shopxx.common.FreemarkerManager" /> -->
    
    <!-- 配置事务管理器 -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	
	<!-- 使用注解方式定义事务 -->
	<tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" />
	
	<!-- 配置事务传播特性
	<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="get*" read-only="true" />
			<tx:method name="load*" read-only="true" />
			<tx:method name="find*" read-only="true" />
			<tx:method name="*" read-only="true" />
		</tx:attributes>
	</tx:advice>
	 -->
	<!-- 哪些类的哪些方法参与事务
	<aop:config>
		<aop:advisor pointcut="execution(* net.shopxx.service..*.*(..))" advice-ref="transactionAdvice" />
	</aop:config> -->
	
	<!-- JCaptcha验证码功能 -->
	<bean id="captchaService" class="com.octo.captcha.service.image.DefaultManageableImageCaptchaService">
		<property name="captchaEngine">
			<bean class="com.deng.common.JCaptchaEngine" />
		</property>
		<!-- 验证码过期时间 -->
		<property name="minGuarantedStorageDelayInSeconds" value="600" />
	</bean>
	
	<!-- SMTP邮件服务 -->
	<bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
		<property name="javaMailProperties">
			<props>
				<prop key="mail.smtp.auth">true</prop>
				<prop key="mail.smtp.timeout">25000</prop>
				<!-- SSL连接 -->
				<!--
				<prop key="mail.smtp.starttls.enable">true</prop>  
				<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
				-->
			</props>
		</property>
	</bean>
	
	<!-- SMTP邮件异步发送 -->
	<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
		<!-- 核心线程数 -->
		<property name="corePoolSize" value="5" />
		<!-- 最大线程数 -->
		<property name="maxPoolSize" value="50" />
		<!-- 最大队列数 -->
		<property name="queueCapacity" value="1000" />
		<!-- 线程池维护线程所允许的空闲时间 -->
		<property name="keepAliveSeconds" value="60" />
	</bean>

</beans>

database.properties

#Dengdie System DATABASE CONFIG
#Sun Nov 27 17:17:26 CST 2011
jdbc.password=123
jdbc.url=jdbc\:mysql\://localhost\:3306/shop_sub_by_me?useUnicode\=true&characterEncoding\=UTF-8
hibernate.cache.use_second_level_cache=false
hibernate.show_sql=true
pool.maxIdleTime=7200
pool.maxIdleTimeExcessConnections=10
jdbc.username=root
hibernate.jdbc.batch_size=30
hibernate.jdbc.fetch_size=50
jdbc.driver=com.mysql.jdbc.Driver
hibernate.hbm2ddl.auto=update
namingStrategy.tablePrefix=shanghu_
hibernate.cache.use_query_cache=false
pool.checkoutTimeout=10000
pool.maxPoolSize=50
hibernate.format_sql=true
namingStrategy.isAddUnderscores=true
hibernate.cache.provider_class=org.hibernate.cache.OSCacheProvider
hibernate.dialect=org.hibernate.dialect.MySQLDialect
pool.initialPoolSize=10
pool.minPoolSize=10
namingStrategy.maxLength=64
pool.acquireIncrement=5

0
rgone
rgone
<body>

		<div class="loginDetail">
			<div class="top">会员注册</div>
			<div class="middle">
				<form id="registerWindowForm" action="/guest/member!ajaxRegister.action" method="post">
					<table>
						<tr>
							<th>用户名</th>
							<td>
								<input type="text" id="loginUsername" name="member.username" class="formText" />
							</td>
						</tr>
						<tr>
							<th>密&nbsp;&nbsp;&nbsp;码</th>
							<td>
								<input type="password" id="loginPassword" name="member.password" class="formText" />
							</td>
						</tr>
						<tr>
							<th>重复密码</th>
							<td>
								<input type="password" id="loginPassword" name="rePassword" class="formText" />
							</td>
						</tr>
						<tr>
							<th>Email</th>
							<td>
								<input type="text" name="member.email" class="formText" />
							</td>
						</tr>
						<tr>
							<th>&nbsp;</th>
							<td>
								<input type="submit" class="submitButton" value="用户注册" hidefocus="true" />
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="bottom"></div>
		</div>
</body>

上面是注册用的html页面!
0
yzw2048
yzw2048
缓存?debug一下,看看有没有返回主键
返回顶部
顶部