Spring の実際の問題を理解するには、構造に関する十分な知識が必要です。この問題について 2 日間検索していますが、解決策が見つかりません。私のプロジェクトでは、ビルド時に Hibernate を使用すると、以下のエラー メッセージが表示されます。
2013-01-17 06:28:50,251 INFO [org.hibernate.cfg.SettingsFactory] - Database ->
name : MySQL
version : 5.0.96-community-nt
major : 5
minor : 0
2013-01-17 06:28:50,251 INFO [org.hibernate.cfg.SettingsFactory] - Driver ->
name : MySQL-AB JDBC Driver
version : mysql-connector-java-5.1.12 ( Revision: ${bzr.revision-id} )
major : 5
minor : 1
2013-01-17 05:13:45,060 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'langService':
Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'langDao' defined in URL [jar:file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/NCFrameworkAdmin/WEB-INF/lib/NCFramework-0.0.1-SNAPSHOT.jar!/com/ns/commerce/framework/lang/dao/LangDaoImpl.class]:
Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/admin-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Wrong column type in db.nc_alert_log for column alerted. Found: bit, expected: TINYINT(1) DEFAULT 0; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/admin-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Wrong column type in db.nc_alert_log for column alerted. Found: bit, expected: TINYINT(1) DEFAULT 0
興味深いのは、blogController と langServices と LangDao が関連していることですが、「nc_alert_log」テーブルについては何もありません。
LangDaoImpl
package com.ns.commerce.framework.lang.dao;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import com.ns.commerce.framework.lang.model.Lang;
import com.ns.commerce.framework.generic.dao.GenericDAOImpl;
@Repository("langDao")
public class LangDaoImpl extends GenericDAOImpl<Lang, Long> implements LangDao {
@Autowired
public LangDaoImpl(@Qualifier("sessionFactory") SessionFactory sessionFactory) {
this.setSessionFactory(sessionFactory);
}
@Override
public Lang findByLocaleCode(String localeCode) {
Criteria criteria = getCriteria();
criteria.add(Restrictions.eq("localeCode", localeCode));
return findByCriteriaFirst(criteria);
}
@Override
public Lang findBySubdomain(String subdomain) {
Criteria criteria = getCriteria();
criteria.add(Restrictions.eq("subdomain", subdomain));
return findByCriteriaFirst(criteria);
}
@Override
public Lang findDefaultLang() {
Criteria criteria = getCriteria();
criteria.add(Restrictions.eq("defaultFlag", true));
return findByCriteriaFirst(criteria);
}
}
AlertLog.Java モデル
@Column(name="alerted", columnDefinition = "TINYINT(1) DEFAULT 0")
private int alerted;
データベース: アラート列 > TINYINT(1) であり、デフォルト値は 0 です。
DB.プロパティ
hibernate.hbm2ddl.auto=validate
#hibernate.hbm2ddl.auto=create-drop
hibernate.hbm2ddl.import_files=/import_standard.sql
hibernate.show_sql=false
hibernate.format_sql=true
hibernate.generate_statistics=false
hibernate.use_sql_comments=true
hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
hibernate.cache.use_second_level_cache=true
#-------------------------------------------------------------------------------
# MySQL Settings
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/asd?autoReconnect=true
jdbc.username=asd
jdbc.password=asd
# Property that determines which Hibernate dialect / MySQL5Dialect || MySQLDialect
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
Pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>NC_Core</artifactId>
<groupId>com.ns.commerce</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>NCFrameworkAdmin</artifactId>
<packaging>war</packaging>
<name>NCFrameworkAdmin Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.nc.commerce</groupId>
<artifactId>NCFramework</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Joda Time Library -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<!-- Jackson JSON Mapper -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</dependency>
<!--Regular Expression Libraries -->
<dependency>
<groupId>oro</groupId>
<artifactId>oro</artifactId>
</dependency>
<dependency>
<groupId>jakarta-regexp</groupId>
<artifactId>jakarta-regexp</artifactId>
</dependency>
<!-- Commons validator -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
</dependency>
<!-- Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
</dependency>
<!-- AOP dependency -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
</dependency>
</dependencies>
<build>
<finalName>NCFrameworkAdmin</finalName>
他のソースが必要な場合は、コメントしてください。