SSH 报错,使用的Hibernate注解,没有使用hmb.xml文件,应用服务器使用的是jetty,启动报错!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSH 报错,使用的Hibernate注解,没有使用hmb.xml文件,应用服务器使用的是jetty,启动报错!相关的知识,希望对你有一定的参考价值。

2013-04-15 11:08:54.423:WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext/web,[file:/D:/code/java/Work/web/WebContent/]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/rdf/configuration/spring/applicationContext-datasource.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/rdf/configuration/spring/applicationContext-datasource.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Duplicate property mapping of version found in com.shinetecnology.cwa.entity.data.CountResultInfoData
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1317)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
.................................
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;

import com.itour.etip.pub.frame.FrmData;
@Entity
@Table(name="COUNT_RESULT")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class CountResultInfoData extends FrmData
private static final long serialVersionUID = 1L;
private String countId;
/**
* 备注
*/
private String remarks;
/**
* 版本
*/
private Integer version;
下面是getXxxx、SetXxxx

/**
* 主键ID取值
*/
@Column(length = 32 , name="COUNT_ID")
public String getCountId()
return countId;


/**
* 主键ID设值
*/

public void setCountId(String countId)
this.countId = countId;

org.hibernate.MappingException: Duplicate property mapping of version found

单看错误信息是提示有重复参数。。
看看是不是CountResultInfoData 中有重复的参数。
还有主键有没有定义。

@Id//定义主键
@GeneratedValue//主键生成策略

你继承了FrmData ,看不到此类代码,你可以自己检查下。追问

问题搞定了,就是因为继承了FrmData,而FrmData里面已经把一些公共的全部写了,所以就报错了,因为是公司的框架,刚进入公司,不明白!谢谢!

追答

解决了就好

参考技术A 嵌套异常org.hibernate.mappingexception:重复的属性映射版本中发现com.shinetecnology.cwa.entity.data.countresultinfodata追问

。。。
我当然知道去翻译一下了 ,主要是我里面没有重复的!全部找过了!

追答

web.xml中是不是配置有问题啊?你可以检查下

hibernate注解HQL 报错

@Entity(name="icertInfo") HQL  查询的时候 需要写Entry 的name值,要不然会报错 iCertInfo is not mapped

	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<!-- 用户名 -->
		<property name="user" value="${db_username}" />
		<!-- 用户密码 -->
		<property name="password" value="${db_password}" />
		<property name="driverClass" value="${db_driver_class}" />
		<property name="jdbcUrl" value="${db_url}" />
		<!--连接池中保留的最大连接数。默认值: 15 -->
		<property name="maxPoolSize" value="20" />
		<!-- 连接池中保留的最小连接数,默认为:3 -->
		<property name="minPoolSize" value="5" />
		<!-- 初始化连接池中的连接数,取值应在minPoolSize与maxPoolSize之间,默认为3 -->
		<property name="initialPoolSize" value="2" />
		<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。默认值: 3 -->
		<property name="acquireIncrement" value="2" />
		<!--定义在从数据库获取新连接失败后重复尝试的次数。默认值: 30 ;小于等于0表示无限次 -->
		<property name="acquireRetryAttempts" value="0" />
		<!--重新尝试的时间间隔,默认为:1000毫秒 -->
		<property name="acquireRetryDelay" value="1000" />
	</bean>
	<!-- 获取hibernate SessionFactory -->
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource">
			<ref bean="dataSource" />
		</property>
		<property name="hibernateProperties">
			<value>
				hibernate.dialect=org.hibernate.dialect.MySQLDialect
				hibernate.show_sql=true
				hibernate.format_sql=true
				hibernate.hbm2ddl.auto=update
			</value>
		</property>
		<property name="packagesToScan">
			<list>
				<value>com.itrus.business.model</value>
			</list>
		</property>
	</bean>

packagesToScan   ,配置错误 HQL 也会报错


package com.itrus.business.properties;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
public class ProInfo extends PropertyPlaceholderConfigurer {
	private static Map<String, Object> ctxPropertiesMap;
	 @Override  
	protected void processProperties(ConfigurableListableBeanFactory beanFactory,  
	            Properties props)throws BeansException {  
	        super.processProperties(beanFactory, props);  
	        ctxPropertiesMap = new HashMap<String, Object>();  
	        for (Object key : props.keySet()) {  
	            String keyStr = key.toString();  
	            String value = props.getProperty(keyStr);  
	            ctxPropertiesMap.put(keyStr, value);  
	        }
	    }
	    public static Object getContextProperty(String name) {  
	        return ctxPropertiesMap.get(name);  
	    }
}



URL=

#AccountHash=

AccountHash=

Password=password

fapiaotong=

certpath=E\://test.cer

db_username=root

#db_password=

db_password=

db_driver_class=com.mysql.jdbc.Driver

#db_url=jdbc\:mysql\://\:3306/hibernate?useUnicode\=true&characterEncoding\=UTF-8

db_url=jdbc\:mysql\://localhost\:3306/hibernate?useUnicode\=true&characterEncoding\=UTF-8

	<!-- 读取配置文件 -->
	<bean id="proinfo" class="com.itrus.business.properties.ProInfo">
		<property name="locations">
			<list>
				<value>classpath:info.properties</value>
			</list>
		</property>
	</bean>



不配置包扫描 查询需要写全名 com.itrus.business.model.ICertInfo

以上是关于SSH 报错,使用的Hibernate注解,没有使用hmb.xml文件,应用服务器使用的是jetty,启动报错!的主要内容,如果未能解决你的问题,请参考以下文章

批量产生ssh2项目中hibernate带注解的pojo类的快捷方法

SSH整合

hibernate添加数据报错:Could not execute JDBC batch update

ssh整合之七注解结合xml形式

ssh全注解整合

SSH整合步骤之注解和非注解