Announcement Announcement Module
Collapse
No announcement yet.
something wrong about Integration with hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • something wrong about Integration with hibernate

    I just make a program which used springframework `s part of orm.hibernate.
    the beans.xml post below:

    Code:
    <bean
    		class="org.springframework.orm.hibernate.LocalSessionFactoryBean"
    		id="hibernateSessionFactory">
    		<property name="dataSource">
    			<ref local="mySqlDB"/>
    		</property>
    		<property name="mappingResources">
    			<list>
    				<value>User.hbm.xml</value>
    			</list>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
    				<prop key="hibernate.show_sql">true</prop>
    			</props>
    		</property>
    	</bean>
    the DAO class code list below:
    Code:
    public class UserDAO extends HibernateDaoSupport implements IUserDao &#123;
    
    	/* &#40;non-Javadoc&#41;
    	 * @see net.asd.role.common.IUserDao#insertUser&#40;net.asd.role.vo.User&#41;
    	 */
    	public void insertUser&#40;User user&#41; &#123;
    		this.getHibernateTemplate&#40;&#41;.save&#40; user&#41;;
    	&#125;
    
    	/* &#40;non-Javadoc&#41;
    	 * @see net.asd.role.common.IUserDao#deleteUser&#40;net.asd.role.vo.User&#41;
    	 */
    	public void deleteUser&#40;User user&#41; &#123;
    		this.getHibernateTemplate&#40;&#41;.delete&#40; user&#41;;
    	&#125;
    
    	/* &#40;non-Javadoc&#41;
    	 * @see net.asd.role.common.IUserDao#updateUser&#40;net.asd.role.vo.User&#41;
    	 */
    	public void updateUser&#40;User user&#41; &#123;
    		this.getHibernateTemplate&#40;&#41;.save&#40; user&#41;;
    	&#125;
    &#125;
    the User class just is a simple pojo held properties: id( assigned),name,password,description
    My Test code list follow:

    Code:
    		User user = new User&#40;&#41;;
    		user.setName&#40;"root"&#41;;
    		user.setPassword&#40;"root"&#41;;
    		user.setDescription&#40;"this is the root user"&#41;;
    		String str = "web/WEB-INF/classes/beans.xml";
    		ApplicationContext context = new FileSystemXmlApplicationContext&#40; str&#41;;
    		IUserDao dao = &#40; IUserDao&#41;context.getBean&#40;"iUserDao"&#41;;
    		dao.insertUser&#40; user&#41;;
    some error occure when i run them in my eclipse with jdk5.0.

    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'hibernateSessionFactory' defined in file [F:\work\AsdBlog\web\WEB-INF\classes\beans.xml]: Initialization of bean failed; nested exception is java.lang.ExceptionInInitializerError: null
    java.lang.ExceptionInInitializerError
    at net.sf.hibernate.cfg.Configuration.buildSessionFac tory(Configuration.java:750)
    at org.springframework.orm.hibernate.LocalSessionFact oryBean.newSessionFactory(LocalSessionFactoryBean. java:436)
    at org.springframework.orm.hibernate.LocalSessionFact oryBean.afterPropertiesSet(LocalSessionFactoryBean .java:374)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:801)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:249)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:177)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:159)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:177)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:268)
    at org.springframework.context.support.FileSystemXmlA pplicationContext.<init>(FileSystemXmlApplicationC ontext.java:60)
    at test.net.asd.role.common.TestUserDAO.testInserUser (TestUserDAO.java:41)
    at test.net.asd.role.common.TestUserDAO.main(TestUser DAO.java:52)
    Caused by: java.lang.IllegalStateException: Cannot determine classloader
    at net.sf.cglib.core.AbstractClassGenerator.getClassL oader(AbstractClassGenerator.java:165)
    at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:176)
    at net.sf.cglib.core.KeyFactory$Generator.create(KeyF actory.java:177)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:149)

    at net.sf.cglib.core.KeyFactory.create(KeyFactory.jav a:142)
    at net.sf.hibernate.impl.SessionFactoryImpl.<clinit>( SessionFactoryImpl.java:235)
    ... 12 more
    i track into cglib( it has rc2 version),found there is the birthplace:

    Code:
       protected ClassLoader getClassLoader&#40;&#41; &#123;
            ClassLoader t = classLoader;
            if &#40;t == null&#41; &#123;
                t = getDefaultClassLoader&#40;&#41;;
            &#125;
            if &#40;t == null&#41; &#123;
                t = getClass&#40;&#41;.getClassLoader&#40;&#41;;
            &#125;
            if &#40;t == null&#41; &#123;
                throw new IllegalStateException&#40;"Cannot determine classloader"&#41;;
            &#125;
            return t;
        &#125;
    at first, classLoader is null, getDefaultClassLoader() will return null -- It required an static variable `s classLoader,null was returned of course.but ,i don`t understand why following code return null:
    getClass().getClassLoader();

    someone help me ,please.
    best regards.
Working...
X