-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem "main" java.lang.ExceptionInInitializerE
PostPosted: Mon Nov 05, 2012 9:51 am 
Newbie

Joined: Thu Nov 01, 2012 6:53 pm
Posts: 2
It say something is wrong with the main in TestClient.java, SessionUtil.jva and MemberDAO.java but I do not see what the problem is.

Exception in thread "main" java.lang.ExceptionInInitializerError
at member.dao.SessionUtil.<clinit>(SessionUtil.java:41)
at member.dao.MemberDAO.addMember(MemberDAO.java:35)
at member.client.TestClient.main(TestClient.java:46)
Caused by: java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter
at org.hibernate.bytecode.cglib.BytecodeProviderImpl.getProxyFactoryFactory(BytecodeProviderImpl.java:33)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactoryInternal(PojoEntityTuplizer.java:182)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:160)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:302)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:238)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1304)
at member.dao.SessionUtil.<clinit>(SessionUtil.java:38)
... 2 more
Caused by: java.lang.ClassNotFoundException: net.sf.cglib.proxy.CallbackFilter
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
TestClient.java
Code:
package member.client;
import member.dao.MemberDAO;
import member.dao.SessionUtil;
import member.model.Member;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Iterator;
import java.util.List;
/**
* <p>
* This component and its source code representation are copyright protected
* and proprietary to The Trivera Group, Inc., Worldwide D/B/A Trivera Technologies
*
* This component and source code may be used for instructional and
* evaluation purposes only. No part of this component or its source code
* may be sold, transferred, or publicly posted, nor may it be used in a
* commercial or production environment, without the express written consent
* of the Trivera Group, Inc.
*
* Copyright (c) 2010 The Trivera Group, LLC.
* http://www.triveratech.com   http://www.triveragroup.com
* </p>
* @author The Trivera Group Tech Team.
*/
@SuppressWarnings("unused")
public class TestClient {
  private static final Log log = LogFactory.getLog(TestClient.class);
  public static void main(String[] args) {
    log.info("Starting the Member Test Client");
    log.info("Constructing a new Member");
    Member member = new Member("bjones");
    member.setEmail("billy.jones@work.com");
    member.setStreet("987 Maple Street");
    member.setCity("Anytown");
member.setState("ID");
    member.setZipCode("12333");
    member.setCountry("USA");
    log.info("Adding member to DAO");
    MemberDAO dao = new MemberDAO();
    dao.addMember(member);
    log.info("Listing all members");
    @SuppressWarnings("rawtypes")
List list = dao.getAllMembers();
    @SuppressWarnings("rawtypes")
Iterator iter = list.iterator();
    while (iter.hasNext()) {
      log.info(iter.next());
    }
  }
}

SessionUtile.java
Code:
package member.dao;
import org.hibernate.cfg.ImprovedNamingStrategy;
import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* <p>
* This component and its source code representation are copyright protected
* and proprietary to The Trivera Group, Inc., Worldwide D/B/A Trivera Technologies
*
* This component and source code may be used for instructional and
* evaluation purposes only. No part of this component or its source code
* may be sold, transferred, or publicly posted, nor may it be used in a
* commercial or production environment, without the express written consent
* of the Trivera Group, Inc.
*
* Copyright (c) 2010 The Trivera Group, LLC.
* http://www.triveratech.com   http://www.triveragroup.com
* </p>
* @author The Trivera Group Tech Team.
*/
public class SessionUtil {
  private static final Log log = LogFactory.getLog(SessionUtil.class);
  //todo complete this class
  public static final SessionFactory sessionFactory;
  static {
    try {
      // Create the SessionFactory from hibernate.cfg.xml
      Configuration configuration = new Configuration().configure();
      sessionFactory = configuration.buildSessionFactory();
    } catch (Throwable ex) {
      log.error("Initial SessionFactory creation failed." + ex);
      throw new ExceptionInInitializerError(ex);
    }
  }
}

MemberDAO.java
Code:
package member.dao;
import member.model.Member;
import org.hibernate.Transaction;
import org.hibernate.Session;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.List;

/**
* <p>
* This component and its source code representation are copyright protected
* and proprietary to The Trivera Group, Inc., Worldwide D/B/A Trivera Technologies
*
* This component and source code may be used for instructional and
* evaluation purposes only. No part of this component or its source code
* may be sold, transferred, or publicly posted, nor may it be used in a
* commercial or production environment, without the express written consent
* of the Trivera Group, Inc.
*
* Copyright (c) 2010 The Trivera Group, LLC.
* http://www.triveratech.com   http://www.triveragroup.com
* </p>
* @author The Trivera Group Tech Team.
*/

public class MemberDAO {
  private static final Log log = LogFactory.getLog(MemberDAO.class);
  public void addMember(Member member) {
    Session session = SessionUtil.sessionFactory.getCurrentSession();
    Transaction tx = session.beginTransaction();
    session.save(member);
    tx.commit();
  }
  public List getAllMembers() {
    Session session = SessionUtil.sessionFactory.getCurrentSession();
    Transaction tx = session.beginTransaction();
    List result = session.createQuery("From Member").list();
    tx.commit();
    return result;
  }
}


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>
    <!-- Database connection information-->
    <property name="connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
     <property name="connection.url">jdbc:derby://localhost/DVDRental</property>
    <property name="connection.username">sa</property>
    <property name="connection.password">password</property>
    <property name="connection.pool_size">2</property>
     <!--other database related information-->
    <property name="show_sql">true</property>
  <property name="format_sql">true</property>
    <property name="dialect">org.hibernate.dialect.DerbyDialect</property>
    <!-- Session Context class    -->
    <property name="current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
    <!-- Mapping files -->
    <mapping resource="Member.hbm.xml"/>

  </session-factory>
</hibernate-configuration>


Member.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping schema="DVDRENTAL">
 
  <class name="member.model.Member" table="MEMBER">
    <id name="id" column="MEMBER_ID">
      <generator class="identity"/>
    </id>
    <property name="username" column="USERNAME" unique="true"/>
    <property name="email" column="EMAIL"/>
    <property name="active" column="ACTIVE"/>
    <property name="memberSinceDate" column="MEMBERSINCEDATE" type="date"/>
    <join table="ADDRESS" >
      <key column="MEMBER_ID"/>
      <property name="street" column="STREET"/>
      <property name="city" column="CITY"/>
      <property name="state" column="STATE"/>
      <property name="zipCode" column="ZIPCODE"/>
      <property name="country" column="COUNTRY"/>
    </join>

  </class>

</hibernate-mapping>



Top
 Profile  
 
 Post subject: Re: Problem "main" java.lang.ExceptionInInitializerE
PostPosted: Sat Feb 09, 2013 3:54 am 
Newbie

Joined: Thu Nov 01, 2012 6:53 pm
Posts: 2
Problem: Do not have all Hibernate jars.
Download hibernate jar files. That has a lib.
Add the contents of the lib file and the hibernate3.jar to your hibernate user library.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.