facebook

Hibernate Quickstart Errors

  1. MyEclipse Archived
  2.  > 
  3. Documentation
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #248687 Reply

    vab3
    Member

    Running a new install Eclipse 3.1.1, MyEclipse, 4.1.1, MySQL 4.1

    I’m running through the Hibernate Quickstart, and, despite some of the database exmples not matching up, I continued to follow the instructions:

    1) I created an “echo_message” table by running the SQL statement that was provided
    2) I went into the database explorer, right-clicked to generate the hibernate mappings
    3) I created the HibernateTest class and pasted in the code provided (see below), adding a few import statements.
    4) When I “run as java application” I get the error below.
    5) I’m also getting all a little messages in the edit window that says “The import net.sf.hibernate cannot be resolved”, which i’m guessing is the problem.

    Where is net.sf.hibernate? How do I resolve it? Am I on the right track or do you need to know more?

    ————————–error message—————————————-
    Exception in thread “main” java.lang.Error: Unresolved compilation problem:

    at com.genuitec.hibernate.HibernateTest.main(HibernateTest.java:11)
    ————————–end error message—————————————-

    —————— provided code from tutorial———————-
    package com.genuitec.hibernate;
    import net.sf.hibernate.*;

    // a few lines I added
    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.Transaction;

    public class HibernateTest {
    public static void main(String[] args) {
    // Step 1 – Create a new entity
    EchoMessage message = new EchoMessage();
    // Step 2 – Set message field
    message.setMsg(“Hello Hibernate, from MyEclipse!”);

    try {
    // Step 3 – Get a Hibernate Session
    Session session = SessionManager.currentSession();
    // Step 4 – Persist entity to database
    Transaction tx = session.beginTransaction();
    session.save(message);
    tx.commit();
    System.out.println(“Save successful.”);
    } catch (HibernateException e) {
    System.out.println(“Save failed.”);
    } finally {
    try {
    // Step 5 – close the session
    SessionManager.closeSession();
    } catch (HibernateException e1) {
    // do nothing
    }
    }
    }
    }
    —————— end provided code from tutorial———————-[/list]

    #248691 Reply

    Greg
    Member

    Remove the import line provided by the tutorial. Then on any of the classes that Eclipse marks as needs to be resolved, use the “Quick tip” on the left and let it auto-resolve the correct import. Do this for all of the unresolved classes and you should be able to compile without any problems.

    #248694 Reply

    Brian Fernandes
    Moderator

    Note that the tutorial is based on Hibernate 2, which uses net.sf.hibernate.* packages, while you probably added Hibernate 3 capabilities (this is the default).
    The package names in Hibernate 3 have been changed to org.hibernate.* – if you make those changes in your calss file, you should be fine.
    As Greg suggests, you can delete all the import and then use “quick tip” or Organize imports (Ctrl + Shift + O) to correct the situation.

    The documentation and tutorials are being updated, sorry for the inconvenience caused.
    Brian.

    #248728 Reply

    vab3
    Member

    Who needs a tutorial when you can get a response at 2 AM? Thank you.

    Removing this line from my code (see above) worked:

    import net.sf.hibernate.*;
Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Hibernate Quickstart Errors

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