-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Error creating bean with name 'sessionFactory'
PostPosted: Wed Jan 09, 2008 2:00 pm 
Beginner
Beginner

Joined: Mon Jan 07, 2008 4:13 am
Posts: 22
Hi,

i have big problem with Hibernate 3.2.5.ga, Hibernate Annotations 3.3.0.GA and Spring 2.5, tomcat 6.0.14, acegi 1.0.6 (and ehcache 1.3.0)

in applicationContext-resources.xml :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
   <property name="driverClassName" value="org.postgresql.Driver" />
   <property name="url" value="jdbc:postgresql://localhost:5432/xxx" />
   <property name="username" value="xxx" />
   <property name="password" value="iwtbxfm" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="hibernateProperties">
            <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
            <prop key="hibernate.query.substitutions">true 'T', false 'F'</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.hibernate.generate_statistics">true</prop>

            <prop key="hibernate.cache.use_second_level_cache">false</prop>

            <prop key="hibernate.cache.provider_configuration_file_resource_path">classpath:/ehcache.xml</prop>
            </props>
        </property>
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="classpath:/hibernate.cfg.xml"/>
    </bean>

</beans>



hibernate.cfg.xml:

Code:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>

        <mapping class="com.xxx.model.Carrier"/>
    </session-factory>
</hibernate-configuration>




BUT after build of project a have this error:

Code:
INFO: Initializing Spring root WebApplicationContext
9.1.2008 18:43:15 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext-resources.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to load class declared as <mapping class="com.xxx.model.Carrier"/> in the configuration:
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1362)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
   at java.security.AccessController.doPrivileged(Native Method)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:407)
   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:735)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
   at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:251)
   at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:190)
   at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
   at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
   at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
   at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
   at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
   at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
   at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
   at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1206)
   at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
   at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
   at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
   at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
   at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
   at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
   at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.MappingException: Unable to load class declared as <mapping class="com.freightservice.model.Carrier"/> in the configuration:
   at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:602)
   at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1443)
   at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:572)
   at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1390)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1359)
   ... 30 more
Caused by: java.lang.ClassNotFoundException: com.freightservice.model.Carrier
   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
   at java.lang.ClassLoader.loadClassInternal(Unknown Source)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Unknown Source)
   at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
   at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:599)
   ... 38 more
9.1.2008 18:43:15 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext


Carrier.java:

Code:

package com.xxx.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;

@Entity @Table(name="carrier")
@javax.persistence.SequenceGenerator(
    name="seq_carrier",
    sequenceName="s_carrier",
    allocationSize=1
)

public class Carrier extends BaseObject {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq_carrier")
    private Long id;

    private String name = null;

    private String address = null;

    public Carrier() {}

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address){
        this.address = address;
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Carrier)) {
            return false;
        }

        final Carrier carrier = (Carrier) o;

        return !(name != null ? !name.equals(carrier.getName()) : carrier.getName() != null);

    }

    public int hashCode() {
        return (name != null ? name.hashCode() : 0);
    }

    public String toString() {
        return null;
    }
}



in web.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>xxx</display-name>

    <!-- Context Configuration locations for Spring XML files -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:/applicationContext.xml
            classpath:/applicationContext-resources.xml
            classpath:/applicationContext-dao.xml
            classpath:/applicationContext-service.xml
            classpath:/applicationContext-business.xml
            classpath:/applicationContext-acegi.xml
        </param-value>
    </context-param>

    <servlet>
        <servlet-name>xxx</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:/webApplicationContext.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>xxx</servlet-name>
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>Acegi Filter Chain Proxy</filter-name>
        <filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
        <init-param>
            <param-name>targetClass</param-name>
            <param-value>org.acegisecurity.util.FilterChainProxy</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>Acegi Filter Chain Proxy</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>




please, where is the problem ?

thanks!

Ivan


Top
 Profile  
 
 Post subject: Re: Error creating bean with name 'sessionFactory'
PostPosted: Wed Jan 09, 2008 6:06 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
It's here:

Code:
Caused by: java.lang.ClassNotFoundException: com.freightservice.model.Carrier


Are you packing this class with your application? What is the layout of the war file?




Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 6:13 pm 
Beginner
Beginner

Joined: Mon Jan 07, 2008 4:13 am
Posts: 22
sorry, this is my mistake, it is not
<mapping class="com.freightservice.model.Carrier"/>
but
<mapping class="com.xxx.model.Carrier"/>
in error message.
i renamed my application, but i sent "message body" to this forum from previous versin of it. Sorry!
Ivan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 6:16 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
termi wrote:
sorry, this is my mistake, it is not
<mapping class="com.freightservice.model.Carrier"/>
but
<mapping class="com.xxx.model.Carrier"/>
in error message.
i renamed my application, but i sent "message body" to this forum from previous versin of it. Sorry!
Ivan


Then I guess it is now complaining it can not find com.xxx.model.Carrier and it is still the same problem. do you package this class with the war file?



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 6:24 pm 
Beginner
Beginner

Joined: Mon Jan 07, 2008 4:13 am
Posts: 22
I have not WAR file, this project is still under development, this web applicatin, in web-inf/classes/com/xxx/model is Carrier.java compiled sucessfully.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 10:17 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
termi wrote:
I have not WAR file, this project is still under development, this web applicatin, in web-inf/classes/com/xxx/model is Carrier.java compiled sucessfully.


I can't tell much from this since the exception is a ClassNotFoundException and you will need to make sure this class is picked correctly. Do a clean deploy and make sure the files are copied in the right path. Meanwhile you can wait to see if anyone else has had a similar problem. It's also possible I am missing something here.


Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.