Hibernate framework configuration instructions

Download  Hibernate  , open the address  www.hibernate.org  , click  Hibernate ORM -> Downloads  to download version  4.3.11  , to use Hibernate  , you need to copy the  required  directory and  optional\c3p0  under  Lib  to the WEB-INF\lib  directory of the site, where The  required  directory is the required library for  Hibernate  ; the optional\c3p0  directory is the required library for the C3P0 data source; the data source driver is also copied to the  WEB-INF\lib  directory. If it is a MySQL database, it can be downloaded from the www.mysql.com site. 

  1. Hibernate  configuration file, you can use the  *.properties  property file, you can also use the XML file configuration, the following uses the XML file configuration:
    1. The configuration file structure is as follows:

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE hibernate-configuration PUBLIC

      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

      "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

      <hibernate-configuration>

      <session-factory>

              <property name=" property name "> property value </property>

    ...  multiple property configurations         

            <mapping class=" The class name of the persistent class "/>

    ...  class names of multiple persistent classes

    </session-factory>

    </hibernate-configuration>

    1. property  description
      1. C3P0  attribute name  connection.driver_class : Specifies the driver used to connect to the database, MySQL  example  com.mysql.jdbc.Driver
      2. C3P0  attribute name  connection.url : specify the connection  URL of the database , MySQL example  jdbc:mysql:// database server address / database name
      3. C3P0  attribute name  connection.username : database login user name
      4. C3P0  attribute name  connection.password : database login user password
      5. C3P0  property name  dialect : Specifies the dialect of the database, MySQL  example  org.hibernate.dialect.MySQLInnoDBDialect
      6. C3P0  property name  hibernate.c3p0.max_size : the maximum number of connections in the connection pool
      7. C3P0  attribute name  hibernate.c3p0.min_size : the minimum number of connections in the connection pool
      8. C3P0  property name  hibernate.c3p0.timeout : Specify the connection timeout period in the connection pool
      9. C3P0  property name  hibernate.c3p0.max_statements : Specify the maximum number of  Statements cached by the connection pool
      10. C3P0  property name  hibernate.c3p0.idle_test_period :
      11. C3P0  property name  hibernate.c3p0.validate :
      12. Property name  show_sql : Displays the SQL generated by  Hibernate  persistence
      13. Property name  hibernate.format_sql : Format the SQL script and then output it
      14. Property name  hibernate.use_sql_comments : Whether to add comments to Hibernate -generated SQL statements that are helpful for debugging
      15. Property name  hibernate.jdbc.batch_size : Specifies the size of the JDBC2  batch update, integer value
      16. Attribute name  hbm2ddl.auto : operate on table structure
        1. Value  create :  every time hibernate is loaded , the last generated table will be deleted, and then a new table will be regenerated according to your model class, even if there is no change twice;
        2. The value of  create-drop : a table is generated  according to the model class every time hibernate is loaded , but as soon as the sessionFactory is closed , the table is automatically deleted;
        3. Value  update :  When hibernate is loaded for the first time , the table structure will be automatically established according to the model class (provided that the database is established first), and the table structure will be automatically updated according to the  model class when hibernate is loaded later , even if the table structure has changed, but the rows in the table Still there will not delete the previous row. It should be noted that when deployed to the server, the table structure will not be established immediately, it will not be established until the application is run for the first time;
        4. Value  validate :  every time hibernate is loaded , the database table structure is verified to be created, it will only be compared with the tables in the database, no new tables will be created, but new values ​​will be inserted
      17. Property name  hibernate.current_session_context_class : Set the underlying implementation type of  SessionFactory.getCurrentSession() 
        1. Value  thread : Implemented using  org.hibernate.context.ThreadLocalSessionContext  to track and delimit the context-related  Session through the currently executing thread
        2. Value  jta : Implemented using  org.hibernate.context.JTASessionContext  to track and delimit context-related  Sessions according to JTA
        3. Value  managed : org.hibernate.context.ManagedSessionContext  implementation, tracking and defining the context-related Session through the currently executing thread , but the program needs to use the static method of the entire class to bind and unbind the Session instance, it will not be automatically opened , flush or close
    2. mapping  description
      1. Attribute  class : The class name of the persistent class
      2. Attribute  resource : mapping file of persistent class

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324650750&siteId=291194637