Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ Hibernate in profile     - The execution order of Oracle WHERE condition is not from right to left (Database)

- Ubuntu install video playback software SMPlayer 14.9.0.7042 (Linux)

- Debian (Wheezy) Install Java environment / replace OpenJDK as the SUN JDK (Linux)

- How VirtualBox and VMware virtual machine conversion (Linux)

- Linux, modify / etc / profile file (Linux)

- Oracle LONG RAW BLOB CLOB type of presentation (Database)

- Oracle PLS-00231 error analysis (Database)

- Oracle large table to clean truncate .. reuse storage (Database)

- To compile install and test Swift under Linux (Linux)

- RMAN backup file is much larger than the size of the database Cause Analysis (Database)

- Log in CentOS 6.5 Multi-user setting VNC (Server)

- Oracle database NUMBER (x, y) data types (Database)

- Java Virtual Machine Basics (Programming)

- Heartbeat (v1, v2, pacemaker) cluster components Overview (Server)

- Linux into single user mode to modify the administrator password (Linux)

- Install Java on RHEL6 (Linux)

- Debian 7.8 system installation and configuration process (Linux)

- Java multi-threaded communications pipeline flow (Programming)

- Linux text processing tool of sed (Linux)

- Run two MySQL service on one server (Database)

 
         
  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:      
 
- Use cmake to compile and install MySQL 5.5 (Database)
- 20 Advanced Java interview questions summary (Programming)
- How to troubleshoot Windows and Ubuntu dual system time is not synchronized (Linux)
- Without Visual Studio .NET Windows application development (Programming)
- Six Ways to view slides can be implemented Android (Programming)
- Linux reserves the rest of the file to delete several (Linux)
- RabbitMQ tutorial examples: the Hello RabbitMQ World Java realization (Linux)
- Oracle 11g tracking and monitoring system-level triggers to drop misuse (Database)
- Oracle procedure or function Empty Table (Database)
- Git / Github use notes (Linux)
- CentOS 6.5 install VNC-Server (Linux)
- CentOS7 boot systemd introduction and use of management (Linux)
- To obtain installation package (RPM) under RHEL6 (Linux)
- How to enable fbcon in Debian (Linux)
- Java Generics (Programming)
- Some MySQL interview questions (Database)
- JavaScript property of checkbox.disabled (Programming)
- Linux unpack the tar file to a different directory (Linux)
- Introduces Linux kernel compilation system and compiler installation (Linux)
- redis configuration in detail (English) (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.