Reputation: 3867
To understand what real problem in Spring is really needs well knowledge about structure. I am seaching about this issue for two days and cant find any solution. In my project, using Hibernate when I build it gives the error message below:
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
The interesting thing is blogController, langServices and LangDao is related, however they have nothing about "nc_alert_log" table.
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 Model
@Column(name="alerted", columnDefinition = "TINYINT(1) DEFAULT 0")
private int alerted;
On the Database: Alerted Column > TINYINT(1) and deafult value is 0.
DB.properties
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>
If any other source needed please comment.
Upvotes: 0
Views: 860
Reputation: 953
nc_alert_log and LangDao are not directly related, but LangDao and the hibernate sessionFactory are. The sessionFactory cant be created because the database definition is wrong. The eror indicates the columntype in the database isn't TINYINT, but BIT (boolean). That's why the sessionFactory fails to start. Without a sesionFactory the LangDao can't be created etc etc.
Upvotes: 1
Reputation: 22710
Wrong column type in db.nc_alert_log for column alerted.
Found: bit, expected: TINYINT(1) DEFAULT 0
Causing the issue. Check type of alerted
column in database and make sure you are using the same in AlertLog.java
.
Upvotes: 1