1. Develop entity classes
Package Com. Persia. JPA; Import Javax. Persistence. entity; Import Javax. Persistence. generatedvalue; Import Javax. Persistence. ID; @ entity Public Class Person { Private Int ID; Private String name; @ ID @ generatedvalue Public Int GETID (){ Return ID ;}Public Void Setid ( Int ID ){ This . ID = ID ;} Public String getname (){ Return Name ;} Public Void Setname (string name ){ This . Name = Name ;}}
2. Add the hibernate attribute in persistence. XML to automatically create a database table through deployment.
<? XML version = "1.0" encoding = "UTF-8" ?> < Persistence Xmlns = Http://java.sun.com/xml/ns/persistence" Xmlns : Xsi = Http://www.w3.org/2001/XMLSchema-instance" Xsi : Schemalocation = Http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" Version = "1.0" > < Persistence - Unit Name = "Jpa01pu" Transaction - Type = "JTA" > < JTA - Data - Source > Java:/JPA </ JTA -Data-Source> < Properties > < Property Name = "Hibernate. dialect" Value = "Org. hibernate. dialect. mysqldialect" /> < Property Name = "Hibernate. hbm2dll. Auto" Value = "Update" /> </ Properties > </ Persistence -Unit > </ Persistence >
I didn't generate a table automatically here, and I don't know where to configure it.