Problems creating a hibernate hello wold project

ok I spent more than 2 days searching for textbooks and a guide on creating a sleep mode project, but I can’t get it to work,

therefore, I have two main questions.

  • Are my assumptions on how to use the hibernate framework correctly?

  • If so, how do I proceed with each step?

Here are my assumptions

1a. I am completing the data modeling phase and a ready-made diagram for use in the application. (Done)

1b. Then I create a relational mapping of objects, which means creating physical classes to map to each relation. (I created these classes using NetBeans: New-> Entity Classes from the database. Will this work, or do I need to use hibernate somehow to create them?)

1c. I need to have hibernate jars in my application class path and some configuration / settings files

1g I load these configuration / settings files

1st Start using hibernate

Now all the training materials that I saw do not specify the detailed information on how to take these steps, I have many tables that I cannot create for all classes manually. Can someone give a short solution? Sort of:

for 1b, create object classes with this command: hibernate-object.jar -db -classes

1c to create settings / configuration file using command / plugin anyway

1d this is how you load these files into code

+4
source share
3 answers

hibernate, ( ) - .

Java- Hibernate .

XML, Hibernate Java (middle-out).

, HibernateUtil :

public class HibernateUtil {

  private static final SessionFactory sessionFactory = buildSessionFactory();

  private static SessionFactory buildSessionFactory() {
    try {
        // Create the SessionFactory from hibernate.cfg.xml
        return new Configuration().configure("myproject.cfg.xml").buildSessionFactory();
    } catch (Throwable ex) {
        // Make sure you log the exception, as it might be swallowed
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
  }

  public static SessionFactory getSessionFactory() {
    return sessionFactory;
  }

  public static void shutdown() {
    // Close caches and connection pools
    getSessionFactory().close();
  }

}

SessionFactory , . , , , Spring.

0

, Hibernate:

  • , , .
  • , @Igor Sadovnikov.
  • , 1: N.

ORM (Netbeans ), . , , ORM.

P.S.: , ...

0

1B, - NetBeans, , . . :

1) download a set of official JARs JARs + JAR-server JAR (this will be configured for the database you are using)

2) Add these libraries to the build path of your project.

3) Start using hibernate

If you use NetBeans, this is not of primary importance, I would suggest you switch to Eclipse, since it is unlikely that you will find few tutorials (in the future) that use NetBeans.

0
source

All Articles