Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ Hibernate in profile     - openSUSE 13.1 / 13.2 installation SoundConverter 2.1.2 (Linux)

- How to install Go1.5 source development environment on Mac (Server)

- Java memory area and memory overflow exception (Programming)

- Five strokes to find out the IP address you want to know (Linux)

- 5 interesting Linux command line tips (Linux)

- Java Foundation - Getting Start (Programming)

- Compare Swift achieve rapid sorting and sorted Methods (Programming)

- Vi (Vim) keyboard map and its basic commands (Linux)

- Nginx is used to build the cache module srcache_nginx (Server)

- Linux smart small switch rfkill (Linux)

- Ubuntu rights management common commands (Linux)

- Using monitoring tool dsniff (Linux)

- [Android] Eclipse does not update the Android SDK Manager solution [using GoAgent] (Programming)

- To use iostat display I / O status under Linux (Linux)

- Compile and install the latest version of Redis Stable (Database)

- To install JDK1.7 and compiler Hadoop-2.7.1 under CentOS7 (Server)

- How to create a remote (Linux)

- Linux 101 hack book reading notes (Linux)

- Linux, Google Test (GTest) test environment to build step (Linux)

- JavaScript object - Flexible and dangerous (Programming)

 
         
  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:      
 
- Linux server remote user to obtain root privileges prevention (Linux)
- Linux install Samba file sharing server (Server)
- Processor in protected mode of protection (Linux)
- Recovery from MySQL master data consistency summary (Database)
- Depth understanding of C language (Programming)
- Installation and deployment of Hadoop 2.7.1 on Ubuntu 14.04 LTS (Server)
- Binary search -Java achieve (Programming)
- CentOS6.5 installation Docker (Linux)
- Java NIO2: Buffer (Programming)
- The formatted Linux hard drive and mount (Linux)
- NGINX Plus now fully supports HTTP / 2 (Server)
- To install GCC development environment under SUSE11 (Linux)
- RedHat / CentOS ext4 partition can not be formatted large supplementary ext4 formatting (Linux)
- C / C ++ various data types Conversion Summary (Programming)
- SSH without password (Linux)
- MySQL full-index scan bug (Database)
- How to make GRub instead of the default Ubuntu software center (Linux)
- Use custom backup plans for Debian backupninja (Linux)
- mysqldump MySQL command-line tool (Database)
- Oracle DataGuard principles and basic configuration (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.