SlideShare a Scribd company logo
hibernate                                   sql           import.sql




          LTEX Documented By
          A                                      http://blog.csdn.net/shadowkiss

                                               2009-7-6


                        Hibernate                                 ddl                      im-
    port.sql                classpath                                         hibernate.cfg.xml


1   < property name = " hbm2ddl . auto " > create </ property >
2   or
3   < property name = " hbm2ddl . auto " > create - drop </ property >


                      import.sql                              JVM                 file.encoding
                                        *nix
                  Windows           OS                                                 JVM
               -Dfile.encoding=UTF-8                                 console

                                           UTF-8
                                                          SchemaExport.java :
1   package org . hibernate . tool . hbm2ddl ;
2   ...
3   public class SchemaExport {
4   ...
5         public void execute ( boolean script , boolean export , boolean
               justDrop , boolean justCreate ) {

                                                  1
6   ...
7                           InputStream stream = ConfigHelper .
                                 getResourc e AsSt r eam ( importFile ) ;
8                           importFileReader = new InputS treamR eader ( stream ) ;
9   ...


                                    Hibernate                   JVM                             (
    new InputStreamReader                                  )       SchemaExport




      (I)      classpath                   import.sql.UTF-8


     (II)                                                          import.sql


       1    package cn . qdqn . bms . web . listener ;
       2
       3    import java . io . File ;
       4    import java . io . FileOutputStream ;
       5    import java . io . IOException ;
       6    import java . io . InputStreamReader ;
       7    import java . io . OutputSt re amWrit er ;
       8    import java . io . Reader ;
       9    import java . io . Writer ;
      10    import java . net . URI ;
      11    import java . net . URISyntaxE xc eption ;
      12
      13    import javax . servlet . Ser vlet C onte x tE v e nt ;
      14    import javax . servlet . S er v l e t Co n te x t L i s t e n e r ;
      15
      16    public class HibListener implements S e r v l e t C o n t e x t L i s t e n e r {
      17
      18          /* *
      19              *
      20              */
      21          public void contextDestroyed ( Se r v le t C on t e xt E v en t sce ) {
      22
      23          }


                                                      2
24
25   /* *
26    *
27    */
28   public void contextIn it ialize d ( S er v l et C o nt e x tE v e nt sce ) {
29          String fileName = sce . getSe rvletC ontext () .
                 getInitParameter ( " ddl " ) ;
30          sce . getServletContext () . log ( " Convert " + fileName + "
                 to import . sql " ) ;
31          String srcEnc = fileName . substring ( fileName .
                 lastIndexOf ( " . " ) + 1) ;
32          //      import.sql
33          File importsqlfile = null ;
34          try {
35                importsqlfile = new File ( new URI ( Thread .
                      currentThread ()
36                          . ge t Con tex t Cl a s s L o a d e r () . getResource ( " " )
37                          + " import . sql " ) ) ;
38          } catch ( URISynt ax Except io n e ) {
39                e . printStackTrace () ;
40          }
41
42          //
43          Reader reader = null ;
44          Writer writer = null ;
45          try {
46                reader = new InputStreamR eader ( Thread .
                      currentThread ()
47                          . ge t Con tex t Cl a s s L o a d e r () .
                                 ge tRes o urce A sS t r ea m ( fileName ) ,
48                          srcEnc ) ;
49
50                writer = new OutputS tr ea mW ri te r (
51                          new FileOutputStream ( importsqlfile ) ,
                                 System
52                                       . getProperty ( " file . encoding " ) ) ;
53
54                int c = -1;
55                StringBuffer tempSB = new StringBuffer () ;
56                while (( c = reader . read () ) != -1) {


                                         3
57                               writer . write ( c ) ;
 58                               tempSB . append (( char ) c ) ;
 59                          }
 60                          sce . getServlet Contex t () . log ( tempSB . toString () ) ;
 61                          //
 62                          sce . getServlet Contex t () . log (
 63                                     " Generate import . sql ( "
 64                                                + System . getProperty ( " file .
                                                        encoding " )
 65                                                + " ) success ! " ) ;
 66                     } catch ( Exception e ) {
 67                          e . printStackTrace () ;
 68                     } finally {
 69                          try {
 70                               reader . close () ;
 71                               writer . flush () ;
 72                               writer . close () ;
 73                          } catch ( IOException e ) {
 74                               e . printStackTrace () ;
 75                          }
 76                     }
 77             }
 78
 79     }


(III)           web.xml                                                      SessionFactory
            ,   ssh                       Spring ContextLoaderListener
  1             <! --                hibernate ddl                     import.sql -- >
  2             <! --                                      -- >
  3             < context - param >
  4                     < param - name > ddl </ param - name >
  5                     < param - value > import . sql . UTF -8 </ param - value >
  6             </ context - param >
  7             < listener >
  8                     < listener - class >
  9                          cn . qdqn . bms . web . listener . HibListener
 10                     </ listener - class >
 11             </ listener >




                                                   4
5

More Related Content

PPTX
PDF
Pf: the OpenBSD packet filter
PDF
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
PPTX
The Art of JVM Profiling
PPTX
Jersey framework
PDF
こわくないよ❤️ Playframeworkソースコードリーディング入門
PDF
Clojure and Modularity
PDF
Everything you wanted to know about Stack Traces and Heap Dumps
Pf: the OpenBSD packet filter
Csw2016 gong pwn_a_nexus_device_with_a_single_vulnerability
The Art of JVM Profiling
Jersey framework
こわくないよ❤️ Playframeworkソースコードリーディング入門
Clojure and Modularity
Everything you wanted to know about Stack Traces and Heap Dumps

What's hot (20)

PDF
Vert.X: Microservices Were Never So Easy (Clement Escoffier)
PDF
Relayd: a load balancer for OpenBSD
PDF
swift-nio のアーキテクチャーと RxHttpClient
PPTX
Do we need Unsafe in Java?
PDF
Csw2016 gawlik bypassing_differentdefenseschemes
PDF
Python twisted
PDF
Linux seccomp(2) vs OpenBSD pledge(2)
PDF
Preparation for mit ose lab4
PDF
OWASP Proxy
PPTX
Down to Stack Traces, up from Heap Dumps
PDF
Devinsampa nginx-scripting
PDF
Java Runtime: повседневные обязанности JVM
PDF
RestMQ - HTTP/Redis based Message Queue
PDF
PostgreSQL and PL/Java
PDF
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
PDF
Using ngx_lua in UPYUN
PDF
Nodejs - A quick tour (v6)
PDF
PDF
Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
PPTX
From 'dotnet run' to 'hello world'
Vert.X: Microservices Were Never So Easy (Clement Escoffier)
Relayd: a load balancer for OpenBSD
swift-nio のアーキテクチャーと RxHttpClient
Do we need Unsafe in Java?
Csw2016 gawlik bypassing_differentdefenseschemes
Python twisted
Linux seccomp(2) vs OpenBSD pledge(2)
Preparation for mit ose lab4
OWASP Proxy
Down to Stack Traces, up from Heap Dumps
Devinsampa nginx-scripting
Java Runtime: повседневные обязанности JVM
RestMQ - HTTP/Redis based Message Queue
PostgreSQL and PL/Java
[2012 CodeEngn Conference 06] pwn3r - Secuinside 2012 CTF 예선 문제풀이
Using ngx_lua in UPYUN
Nodejs - A quick tour (v6)
Feldo: Function Event Listing and Dynamic Observing for Detecting and Prevent...
From 'dotnet run' to 'hello world'
Ad

Viewers also liked (8)

PPT
Woody's Quotes
PDF
JD James - What we do
PDF
第七颗头骨 & 忘魂花 凤凰
PPT
Science
PPT
Photo Album2
PPT
Photo Album1
PPT
Skritter @ IALLT
PPT
Gallery
Woody's Quotes
JD James - What we do
第七颗头骨 & 忘魂花 凤凰
Science
Photo Album2
Photo Album1
Skritter @ IALLT
Gallery
Ad

Similar to Hibernate Import.Sql I18n (20)

PDF
JJUG CCC 2011 Spring
PDF
#JavaFX.forReal() - ElsassJUG
PDF
Mobile Programming - Network Universitas Budi Luhur
PDF
Silicon Valley JUG: JVM Mechanics
PDF
Testing with Node.js
PPTX
A topology of memory leaks on the JVM
DOCX
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
PPTX
Jdk 7 4-forkjoin
PDF
ikh331-06-distributed-programming
KEY
JavaOne 2012 - JVM JIT for Dummies
PDF
Construire une application JavaFX 8 avec gradle
PDF
JVM Mechanics: When Does the JVM JIT & Deoptimize?
KEY
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
PDF
wtf is in Java/JDK/wtf7?
ODP
Jersey Guice AOP
PPTX
Anti patterns
PDF
Multithreading in Java
DOCX
DOCX
Code red SUM
PDF
Atlassian Groovy Plugins
JJUG CCC 2011 Spring
#JavaFX.forReal() - ElsassJUG
Mobile Programming - Network Universitas Budi Luhur
Silicon Valley JUG: JVM Mechanics
Testing with Node.js
A topology of memory leaks on the JVM
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
Jdk 7 4-forkjoin
ikh331-06-distributed-programming
JavaOne 2012 - JVM JIT for Dummies
Construire une application JavaFX 8 avec gradle
JVM Mechanics: When Does the JVM JIT & Deoptimize?
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
wtf is in Java/JDK/wtf7?
Jersey Guice AOP
Anti patterns
Multithreading in Java
Code red SUM
Atlassian Groovy Plugins

Recently uploaded (20)

PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Machine learning based COVID-19 study performance prediction
A Presentation on Artificial Intelligence
Encapsulation_ Review paper, used for researhc scholars
Per capita expenditure prediction using model stacking based on satellite ima...
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation theory and applications.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Assigned Numbers - 2025 - Bluetooth® Document
gpt5_lecture_notes_comprehensive_20250812015547.pdf
A comparative analysis of optical character recognition models for extracting...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Network Security Unit 5.pdf for BCA BBA.
Group 1 Presentation -Planning and Decision Making .pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Machine learning based COVID-19 study performance prediction

Hibernate Import.Sql I18n

  • 1. hibernate sql import.sql LTEX Documented By A http://blog.csdn.net/shadowkiss 2009-7-6 Hibernate ddl im- port.sql classpath hibernate.cfg.xml 1 < property name = " hbm2ddl . auto " > create </ property > 2 or 3 < property name = " hbm2ddl . auto " > create - drop </ property > import.sql JVM file.encoding *nix Windows OS JVM -Dfile.encoding=UTF-8 console UTF-8 SchemaExport.java : 1 package org . hibernate . tool . hbm2ddl ; 2 ... 3 public class SchemaExport { 4 ... 5 public void execute ( boolean script , boolean export , boolean justDrop , boolean justCreate ) { 1
  • 2. 6 ... 7 InputStream stream = ConfigHelper . getResourc e AsSt r eam ( importFile ) ; 8 importFileReader = new InputS treamR eader ( stream ) ; 9 ... Hibernate JVM ( new InputStreamReader ) SchemaExport (I) classpath import.sql.UTF-8 (II) import.sql 1 package cn . qdqn . bms . web . listener ; 2 3 import java . io . File ; 4 import java . io . FileOutputStream ; 5 import java . io . IOException ; 6 import java . io . InputStreamReader ; 7 import java . io . OutputSt re amWrit er ; 8 import java . io . Reader ; 9 import java . io . Writer ; 10 import java . net . URI ; 11 import java . net . URISyntaxE xc eption ; 12 13 import javax . servlet . Ser vlet C onte x tE v e nt ; 14 import javax . servlet . S er v l e t Co n te x t L i s t e n e r ; 15 16 public class HibListener implements S e r v l e t C o n t e x t L i s t e n e r { 17 18 /* * 19 * 20 */ 21 public void contextDestroyed ( Se r v le t C on t e xt E v en t sce ) { 22 23 } 2
  • 3. 24 25 /* * 26 * 27 */ 28 public void contextIn it ialize d ( S er v l et C o nt e x tE v e nt sce ) { 29 String fileName = sce . getSe rvletC ontext () . getInitParameter ( " ddl " ) ; 30 sce . getServletContext () . log ( " Convert " + fileName + " to import . sql " ) ; 31 String srcEnc = fileName . substring ( fileName . lastIndexOf ( " . " ) + 1) ; 32 // import.sql 33 File importsqlfile = null ; 34 try { 35 importsqlfile = new File ( new URI ( Thread . currentThread () 36 . ge t Con tex t Cl a s s L o a d e r () . getResource ( " " ) 37 + " import . sql " ) ) ; 38 } catch ( URISynt ax Except io n e ) { 39 e . printStackTrace () ; 40 } 41 42 // 43 Reader reader = null ; 44 Writer writer = null ; 45 try { 46 reader = new InputStreamR eader ( Thread . currentThread () 47 . ge t Con tex t Cl a s s L o a d e r () . ge tRes o urce A sS t r ea m ( fileName ) , 48 srcEnc ) ; 49 50 writer = new OutputS tr ea mW ri te r ( 51 new FileOutputStream ( importsqlfile ) , System 52 . getProperty ( " file . encoding " ) ) ; 53 54 int c = -1; 55 StringBuffer tempSB = new StringBuffer () ; 56 while (( c = reader . read () ) != -1) { 3
  • 4. 57 writer . write ( c ) ; 58 tempSB . append (( char ) c ) ; 59 } 60 sce . getServlet Contex t () . log ( tempSB . toString () ) ; 61 // 62 sce . getServlet Contex t () . log ( 63 " Generate import . sql ( " 64 + System . getProperty ( " file . encoding " ) 65 + " ) success ! " ) ; 66 } catch ( Exception e ) { 67 e . printStackTrace () ; 68 } finally { 69 try { 70 reader . close () ; 71 writer . flush () ; 72 writer . close () ; 73 } catch ( IOException e ) { 74 e . printStackTrace () ; 75 } 76 } 77 } 78 79 } (III) web.xml SessionFactory , ssh Spring ContextLoaderListener 1 <! -- hibernate ddl import.sql -- > 2 <! -- -- > 3 < context - param > 4 < param - name > ddl </ param - name > 5 < param - value > import . sql . UTF -8 </ param - value > 6 </ context - param > 7 < listener > 8 < listener - class > 9 cn . qdqn . bms . web . listener . HibListener 10 </ listener - class > 11 </ listener > 4
  • 5. 5