Example tutorial of configuration files in Hibernate
First of all, let’s take a look at hibernate’s main configuration file
1 nbsp;hibernate-configuration PUBLIC 2 "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 3 "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 4 5 <hibernate-configuration> 6 <!-- 通常,一个session-factory节点代表一个数据库 --> 7 <session-factory> 8 9 <!-- 1. 数据库连接配置 -->10 <property>com.mysql.jdbc.Driver</property>11 <property>jdbc:mysql:///day17</property>12 <property>root</property>13 <property>root</property>14 <!-- 15 数据库方法配置, hibernate在运行的时候,会根据不同的方言生成符合当前数据库语法的sql16 -->17 <property>org.hibernate.dialect.MySQL5Dialect</property>18 19 20 <!-- 2. 其他相关配置 -->21 <!-- 2.1 显示hibernate在运行时候执行的sql语句 -->22 <property>true</property>23 <!-- 2.2 格式化sql -->24 <property>true</property>25 <!-- 2.3 自动建表 -->26 <property>update</property>27 28 29 <!-- 3. 加载所有映射 -->30 <mapping></mapping>31 32 </session-factory>33 </hibernate-configuration>
The main codes in it are all commented out, and everyone will understand them at a glance. In the nearest part of the xml file, we see There is a code:
<!-- 3. 加载所有映射 --> 3<mapping></mapping> 这是添加一个映射文件,意思就是你要使用的数据库中的表 映射文件为:
<span style="color: #0000ff"></span><span style="color: #ff00ff">xml version="1.0"</span><span style="color: #0000ff">?></span><span style="color: #0000ff"><span style="color: #ff00ff">DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"</span><span style="color: #0000ff">></span><span style="color: #0000ff"><span style="color: #800000">hibernate-mapping </span><span style="color: #ff0000">package</span><span style="color: #0000ff">="cn.itcast.entity"</span><span style="color: #0000ff">></span><span style="color: #0000ff"><span style="color: #800000">class </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="Employee"</span><span style="color: #ff0000"> table</span><span style="color: #0000ff">="employee"</span><span style="color: #0000ff">></span><span style="color: #008000"><!--</span><span style="color: #008000"> 主键 ,映射</span><span style="color: #008000">--></span><span style="color: #0000ff"><span style="color: #800000">id </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="empId"</span><span style="color: #ff0000"> column</span><span style="color: #0000ff">="id"</span><span style="color: #0000ff">></span><span style="color: #0000ff"><span style="color: #800000">generator </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="native"</span><span style="color: #0000ff">/></span><span style="color: #0000ff"></span><span style="color: #800000">id</span><span style="color: #0000ff">></span><span style="color: #008000"><!--</span><span style="color: #008000"> 非主键,映射 </span><span style="color: #008000">--></span><span style="color: #0000ff"><span style="color: #800000">property </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="empName"</span><span style="color: #ff0000"> column</span><span style="color: #0000ff">="name"</span><span style="color: #0000ff">></span><span style="color: #800000">property</span><span style="color: #0000ff">></span><span style="color: #0000ff"><span style="color: #800000">property </span><span style="color: #ff0000">name</span><span style="color: #0000ff">="workDate"</span><span style="color: #ff0000"> column</span><span style="color: #0000ff">="workDate"</span><span style="color: #0000ff">></span><span style="color: #800000">property</span><span style="color: #0000ff">></span><span style="color: #0000ff"></span><span style="color: #800000">class</span><span style="color: #0000ff">></span><span style="color: #0000ff"></span><span style="color: #800000">hibernate-mapping</span><span style="color: #0000ff">><br><br></span></span></span></span></span></span></span></span>
This configuration file is associated with an entity class Employee.java. The value in name is the attribute in the class, and the value in column is the database table employee. The field names in are related through mapping.
The corresponding attribute description in the entity class is:
The corresponding field of the database table employee is:
Associated through mapping files.
As mentioned above, it is a simple hibernate configuration process. If novice readers want to learn, you can just change the part in the above file. The main configuration file mainly involves the database connection, including Database driver, connected database name, database username and password, and the following mapping file to be loaded.
Regarding the modification of the mapping file, you can modify it according to my example above and then apply it to your own example.
If you have any questions, please comment below.
The above is the detailed content of Example tutorial of configuration files in Hibernate. For more information, please follow other related articles on the PHP Chinese website!

JVM'sperformanceiscompetitivewithotherruntimes,offeringabalanceofspeed,safety,andproductivity.1)JVMusesJITcompilationfordynamicoptimizations.2)C offersnativeperformancebutlacksJVM'ssafetyfeatures.3)Pythonisslowerbuteasiertouse.4)JavaScript'sJITisles

JavaachievesplatformindependencethroughtheJavaVirtualMachine(JVM),allowingcodetorunonanyplatformwithaJVM.1)Codeiscompiledintobytecode,notmachine-specificcode.2)BytecodeisinterpretedbytheJVM,enablingcross-platformexecution.3)Developersshouldtestacross

TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec

JVMhasacloserelationshipwiththeOSasittranslatesJavabytecodeintomachine-specificinstructions,managesmemory,andhandlesgarbagecollection.ThisrelationshipallowsJavatorunonvariousOSenvironments,butitalsopresentschallengeslikedifferentJVMbehaviorsandOS-spe

Java implementation "write once, run everywhere" is compiled into bytecode and run on a Java virtual machine (JVM). 1) Write Java code and compile it into bytecode. 2) Bytecode runs on any platform with JVM installed. 3) Use Java native interface (JNI) to handle platform-specific functions. Despite challenges such as JVM consistency and the use of platform-specific libraries, WORA greatly improves development efficiency and deployment flexibility.

JavaachievesplatformindependencethroughtheJavaVirtualMachine(JVM),allowingcodetorunondifferentoperatingsystemswithoutmodification.TheJVMcompilesJavacodeintoplatform-independentbytecode,whichittheninterpretsandexecutesonthespecificOS,abstractingawayOS

Javaispowerfulduetoitsplatformindependence,object-orientednature,richstandardlibrary,performancecapabilities,andstrongsecurityfeatures.1)PlatformindependenceallowsapplicationstorunonanydevicesupportingJava.2)Object-orientedprogrammingpromotesmodulara

The top Java functions include: 1) object-oriented programming, supporting polymorphism, improving code flexibility and maintainability; 2) exception handling mechanism, improving code robustness through try-catch-finally blocks; 3) garbage collection, simplifying memory management; 4) generics, enhancing type safety; 5) ambda expressions and functional programming to make the code more concise and expressive; 6) rich standard libraries, providing optimized data structures and algorithms.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
