Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ Hibernate in profile     - Oracle 11g statistics collection - collection of multi-column statistics (Database)

- The Objects in JavaScript (Programming)

- RedHat yum configuration and the prompt (Linux)

- Ubuntu 14.04, 13.10 install OpenCV 2.4.9 (Linux)

- Linux terminal program running in the background (Linux)

- Linux asynchronous read documents by AIO (Programming)

- BCP importing and exporting large amounts of data Practice (Database)

- Linux 0.12 kernel and modern kernels difference in memory management (Linux)

- Oracle 10g relations with the constraint of column properties NULLABLE (Database)

- Spring JDBC Comments (Programming)

- Advanced Linux security settings (Linux)

- Java String and StringBuffer and StringBuilder Comments (Programming)

- Oracle 12C with multi-column index (Database)

- Ubuntu 14.04 LTS to compile the source code Android4.4.2 (Linux)

- build Android environment on Ubuntu 12.04 (Server)

- Additional SQL Server 5123 database reported error (Database)

- To install Internet security firewall Raiders (Linux)

- ELKstack log analysis platform (Server)

- How to use GRUB2 files directly from the hard disk to run ISO (Linux)

- Give your photos Instagram style filters plus program in ubuntu (Linux)

 
         
  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:      
 
- Singleton (Linux)
- Neo4j map data processing tab (Database)
- 20 Advanced Java interview questions summary (Programming)
- Installation and Configuration rsync server under CentOS 6.3 (Server)
- Installation Mate Desktop in FreeBSD 10.1 (Linux)
- Linux environment RabbitMQ installation and monitoring of plug-in installation (Linux)
- mydumper installation error process (Database)
- Java polymorphic methods inside constructors complete analysis (Programming)
- About the replication of JavaScript (Programming)
- HA-Federation-HDFS + Yarn cluster deployment (Server)
- Linux firewall Iptables study notes (Linux)
- Linux Getting Started tutorial: Experience Xen Virtual Machine chapter (Linux)
- How MySQL tracking sql statement (Database)
- Ubuntu Apache2 setting, problem solving css, pictures, etc. can not be displayed (Server)
- Linux 64-bit porting (Programming)
- Run Windows in FreeBSD bhyve (Linux)
- ISO image to use offline upgrade Ubuntu (Linux)
- Ubuntu users install the video driver Nvidia Driver 334.21 (Linux)
- Introduction and bash history command to quickly call (Linux)
- Teach you how to choose to install CentOS 6.5 installation package (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.