-->
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: Hibernate Running Problem. need help
PostPosted: Sat Jul 03, 2010 6:52 pm 
Newbie

Joined: Sat Jul 03, 2010 6:35 pm
Posts: 2
Hi I'm new to the Hibernate. I'm trying to create HelloWorld example with Hibernate. I'm trying for 3 days to deal errors. I'll be glad if anyone say what's wrong. here my hibernate user library."derby jar should be mysql I changed that"
Image

here's my Employee.java
Code:
import javax.persistence.Entity;
import javax.persistence.Id;


@Entity
public class Employee {

   private int empId;
   private String empName;
   
   @Id
   public int getEmpId() {
      return empId;
   }
   public void setEmpId(int empId) {
      this.empId = empId;
   }
   public String getEmpName() {
      return empName;
   }
   public void setEmpName(String empName) {
      this.empName = empName;
   }
}


here's my hibernate.cfg.xml file
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 settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/HibernateDb</property>
        <property name="connection.username">root</property>
        <property name="connection.password">11</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">2</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Enable Hibernate's current session context -->
        <property name="current_session_context_class">org.hibernate.context.ManagedSessionContext</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

         Drop and re-create the database schema on startup
<!--        <property name="hbm2ddl.auto">create</property>-->
<!---->
<!--        <mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>-->
<!--        <mapping resource="org/hibernate/tutorial/domain/Person.hbm.xml"/>-->

    </session-factory>

</hibernate-configuration>



here my run class
Code:
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class TestEmployee {

   
   public static void main(String[] args) {
      
      AnnotationConfiguration config = new AnnotationConfiguration();
      config.addAnnotatedClass(Employee.class);
      config.configure("hibernate.cfg.xml");
      
      new SchemaExport(config).create(true, true);
         
   }

}


When I Run the application I get these errors
Code:
01:38:48,906  INFO Version:15 - Hibernate Annotations 3.4.0.GA
01:38:48,906  INFO Environment:560 - Hibernate 3.3.2.GA
Exception in thread "main" java.lang.ExceptionInInitializerError
   at org.hibernate.cfg.Configuration.reset(Configuration.java:217)
   at org.hibernate.cfg.AnnotationConfiguration.reset(AnnotationConfiguration.java:233)
   at org.hibernate.cfg.Configuration.<init>(Configuration.java:197)
   at org.hibernate.cfg.Configuration.<init>(Configuration.java:201)
   at org.hibernate.cfg.AnnotationConfiguration.<init>(AnnotationConfiguration.java:108)
   at com.hibernate.chapter1.TestEmployee.main(TestEmployee.java:11)
Caused by: java.lang.NullPointerException
   at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:167)
   at org.hibernate.cfg.Environment.<clinit>(Environment.java:575)
   ... 6 more


Please help me.


Top
 Profile  
 
 Post subject: Re: Hibernate Running Problem. need help
PostPosted: Sun Jul 04, 2010 10:55 am 
Newbie

Joined: Sat Jul 03, 2010 6:35 pm
Posts: 2
I Used hibernate mapping file instead of annotations and my problem solved.


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.