facebook

Exception in thread "main" org.hibernate.exception

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #287846 Reply

    Yersh
    Member

    Hi,
    I am a beginer for hibernate.
    I am writing a simple java class to talk with data base. When i was trying to run the program i was able to see the following error.

    log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
    log4j:WARN Please initialize the log4j system properly.
    Inserting Record
    Done
    Exception in thread “main” org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
    at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:301)
    at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:110)
    at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:76)
    at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:69)
    at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:150)
    at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1839)
    at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
    at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
    at com.practice.first.FirstExample.main(FirstExample.java:37)
    Caused by: java.sql.SQLException: Listener refused the connection with the following error:
    ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
    The Connection descriptor used by the client was:
    localhost:1521:orcl

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:298)
    … 14 more

    Here are my xml file and java classes.
    package com.practice.first;

    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;

    /**
    *
    * Hibernate example to inset data into Contact table
    */
    public class FirstExample {
    public static void main(String[] args) {
    Session session = null;

    try{
    // This step will read hibernate.cfg.xml and prepare hibernate for use
    SessionFactory sessionFactory = new

    Configuration().configure().buildSessionFactory();
    session =sessionFactory.openSession();
    //Create new instance of Contact and set values in it by reading them from form object
    System.out.println(“Inserting Record”);
    Contact contact = new Contact();
    contact.setId(3);
    contact.setFirstName(“Deepak”);
    contact.setLastName(“Kumar”);
    contact.setEmail(“deepak_38@yahoo.com”);
    session.save(contact);
    System.out.println(“Done”);
    }catch(Exception e){
    System.out.println(e.getMessage());
    }finally{
    // Actual contact insertion will happen at this step
    session.flush();
    session.close();
    }
    }
    }
    ___________________________________________________________________
    package com.practice.first;

    /**
    *
    * Java Class to map to the datbase Contact Table
    */
    public class Contact {
    private String firstName;
    private String lastName;
    private String email;
    private long id;

    /**
    * @return Email
    */
    public String getEmail() {
    return email;
    }

    /**
    * @return First Name
    */
    public String getFirstName() {
    return firstName;
    }

    /**
    * @return Last name
    */
    public String getLastName() {
    return lastName;
    }

    /**
    * @param string Sets the Email
    */
    public void setEmail(String string) {
    email = string;
    }

    /**
    * @param string Sets the First Name
    */
    public void setFirstName(String string) {
    firstName = string;
    }

    /**
    * @param string sets the Last Name
    */
    public void setLastName(String string) {
    lastName = string;
    }

    /**
    * @return ID Returns ID
    */
    public long getId() {
    return id;
    }

    /**
    * @param l Sets the ID
    */
    public void setId(long l) {
    id = l;
    }

    }
    __________________________________________________________________
    <?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”&gt;

    <!– Generated by MyEclipse Hibernate Tools. –>
    <hibernate-configuration>

    <session-factory>
    <property name=”connection.driver_class”>oracle.jdbc.driver.OracleDriver</property>
    <property name=”dialect”>org.hibernate.dialect.OracleDialect</property>
    <property name=”connection.username”>portalenv</property>
    <property name=”connection.password”>portalenv</property>
    <property name=”connection.url”>jdbc:oracle:thin:@localhost:1158/em</property>
    <property name=”hibernate.hbm2ddl.auto”>update</property>
    <mapping resource=”contact.hbm.xml”/>

    </session-factory>

    </hibernate-configuration>
    ________________________________________________________________________
    <?xml version=”1.0″?>
    <!DOCTYPE hibernate-mapping PUBLIC
    “-//Hibernate/Hibernate Mapping DTD 3.0//EN”
    http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd”&gt;

    <hibernate-mapping>
    <class name=”com.practice.first.Contact” table=”CONTACT”>
    <id name=”id” type=”long” column=”ID” >
    <generator class=”assigned”/>
    </id>

    <property name=”firstName”>
    <column name=”FIRSTNAME” />
    </property>
    <property name=”lastName”>
    <column name=”LASTNAME”/>
    </property>
    <property name=”email”>
    <column name=”EMAIL”/>
    </property>
    </class>
    </hibernate-mapping>

    Can anybody help me with this?

    #287859 Reply

    Loyal Water
    Member

    Moving to Off Topic >> Software Development.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Exception in thread "main" org.hibernate.exception

You must be logged in to post in the forum log in