Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ Hibernate in profile     - Use install_updates upgrade GAMIT / GLOBK (Linux)

- ORA-00600 error solve one case (Database)

- Upload the project to GitHub, synchronous remote repository Github (Linux)

- Linux system performance analysis and top command ps.pstree Comments (Linux)

- VMware Workstation virtual machine startup error: Could not open / dev / vmmon in CentOS 6 (Linux)

- Perl said method B if A judge (Programming)

- Android components save state series - Activity (Programming)

- Install Git on CentOS (Linux)

- Android screen rotation processing and ProgressDialog the best AsyncTask (Programming)

- Installation configuration CUDA under Ubuntu 14.04 (Linux)

- Spring REST Exception Handling (Programming)

- Install Mac OS X 10.9 systems VMware10 (Linux)

- C ++ inline functions (Programming)

- Ubuntu 14.04 to install file editor KKEdit 0.1.5 version (Linux)

- Use Python to perform system commands common usage (Programming)

- ASP.NET 5 tutorial series (Server)

- FileZilla 3.10.1.1 install on Ubuntu 14.10 (Linux)

- Ubuntu 10.10 install Oracle 10g graphic tutorials (Database)

- Eclipse configuration GTK (Linux)

- Deploy Apache Spark cluster environment in Ubuntu (Server)

 
         
  Hibernate in profile
     
  Add Date : 2018-11-21      
         
         
         
  Persistent objects can have the following three states:

Temporary state (Transient): object temporary state, then the database does not have information about that object in the database before saving, if not persistent, the program exits the temporary state of object information will be lost. Any time may be garbage collected (not in the corresponding record in the database, should be new initialization), and after the execution save () method becomes Persistent objects (persistent objects), not included in the session management, an object in memory, no ID, no cache

Persistent state (Persistent): object persistent state, this time the database has information about the object when after saving into the database or from the database load, and not out of the Session. Because still Session, the persistent state of the object can do anything about the database, the database has a corresponding record exists to include session management. Clean up cache (dirty checking) time, will and database synchronization. There are memory, the cache there, the database has (ID)

Separated state (Detached): For the isolated state is the object had persistent state, but has now left the Session. Although the objects are separated state id value, but has been unable to perform the operation of the relevant database. For example, reading a collection of property lazy loading, you may be thrown LazyInitalizeException.

Profiles

Hibernate also supports dynamic configuration

XML configuration

Configurationcfg = new Configuration () addResource ( "com / clf / Cat.hbm.xml").;

// Annotation configuration

Configuration cfg = new Configuration () addClass (com.clf.bean.cat.Class).;

By setProperty ( "hibernate.dialect", "org.hibernate.dialect.MySQLDialect") similar approach can be dynamically set Hibernate parameters can also be used addProperties (Propertiesp) batch add parameters

General Configuration

Hibernate configuration file can be XML or properties files, the default configuration file name hibernate.cfg.xml or hibernate.properties, located classpath below. properties parameters in the file is a hibernate prefix, but no xml file

hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.connection.url = jdbc: mysql: // localhost:? 3306 / hibernate characterEncoding = UTF-8
hibernate.connection.username = root
hibernate.connection.password = admin
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.show_sql = true
hibernate.hbm2ddl.auto = create
hibernate.current_session_context_class = thread

 

< ? 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>

 < ! - Hibernate is true that will be sent to the database sql displayed ->
 < Property name = "show_sql"> true < / property>

 < -! SQL dialect, is set here MySQL ->
 < Property name = "dialect"> net.sf.hibernate.dialect.MySQLDialect < / property>

 < ! - A number of records in the database read ->
 < Property name = "jdbc.fetch_size"> 50 < / property>

 < ! - Set the database to delete in bulk ->
 < Property name = "jdbc.batch_size"> 30 < / property>

 < ! - Driver ->
 < Property name = "connection.driver_class"> com.mysql.jdbc.Driver < / property>

 < -! JDBC URL ->
 < Property name = "connection.url"> jdbc: mysql:? // Localhost / dbname characterEncoding = gb2312 < / property>

 < ! - Database user name ->
 < Property name = "connection.username"> root < / property>

 < ! - Database password ->
 < Property name = "connection.password"> root < / property>

 < ! - Mapping files ->
 < Mapping resource = "com / amigo / pojo / User.hbm.xml" />
 < Mapping resource = "com / amigo / pojo / Org.hbm.xml" />
< / Session-factory>
< / Hibernate-configuration>

Configure Data Source

< Session-factory>
< ! - The following is JNDI configuration ->
< ! - Name of data source ->
< Property name = "connection.datasource"> java: comp / env / jdbc / datasourcename < / property>

< ! - Data source provider ->
< Property name = "hibernate.jndi.url"> < / property>

< ! - Data source implementation class ->
< Property name = "hibernate.jndi.class"> < / property>

< -! Hibernate connection load class ->
< Property name = "connection.provider_class"> net.sf.hibernate.connection.DatasourceConnectionProvider < / property>

< Property name = "dialect"> net.sf.hibernate.dialect.SQLServerDialect < / property>

< ! - Mapping files ->
< Mapping resource = "com / amigo / pojo / User.hbm.xml" />
< Mapping resource = "com / amigo / pojo / Org.hbm.xml" />
< / Session-factory>

c3p0 connection pool

c3p0 Connection pooling is recommended to use Hibernate connection pool, if the need to use the connection pool, you need to c3p0 jar package was added to the classpath. Configuration example c3p0 connection pool as follows:

< Session-factory>
< Property name = "connection.driver_class"> ...... < / property>

< -! JDBC URL ->
< Property name = "connection.url"> ...... < / property>

< ! - Database user name ->
< Property name = "connection.username"> user < / property>

< ! - Database password ->
< Property name = "connection.password"> pass < / property>

< Property name = "c3p0.min_size"> 5 < / property>

< Property name = "c3p0.max_size"> 20 < / property>

< Property name = "c3p0.timeout"> 1800 < / property>

< Property name = "c3p0.max_statements"> 50 < / property>
......
< / Session-factory>

In the above configuration, Hibernate generates the connection according to the profile, and then to the c3p0 management.
     
         
         
         
  More:      
 
- Wireshark basic introduction and learning TCP three-way handshake (Linux)
- SecureCRT in Python scripting study guide (Programming)
- Linux foreground to background process switch (Linux)
- Linear table with a Java implementation of the iterator (Programming)
- Remote database using RMAN recovery test (RAC return to single-instance database) (Database)
- Shell commonly commands (Linux)
- Use scripts easily install the latest Linux kernel in Ubuntu (Linux)
- Android memory optimization of the disk cache (Linux)
- ARP Linux-related operations (Linux)
- Django template inheritance child (Programming)
- How to use the on-screen keyboard in Linux (Linux)
- Examples of RAID levels and achieve Operational Details (Linux)
- Spring MVC Exception Handling (Programming)
- Sort search algorithm Java - application examples with recursive dichotomy (Programming)
- Linux environment installation of rvm and ruby (Linux)
- Linux environment variable configuration and save places (Linux)
- Java developers question (Programming)
- FileZilla 3.10.1.1 install on Ubuntu 14.10 (Linux)
- Zombie process under Linux (Linux)
- MySQL database master never solve the synchronization method (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.