1. automatically generate a table by Annotation
<? 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 = "Jpamanytoonepu" Transaction - Type = "JTA" > < JTA - Data -Source > Java:/JPA </ JTA -Data-Source > < Properties > < Property Name = "Hibernate. dialect" Value = "Org. hibernate. dialect. mysqldialect" /> < Property Name = "Hibernate. hbm2ddl. Auto" Value = "Update" /> </ Properties > </ Persistence -Unit > </ Persistence >
Last time Yes<Property Name="Hibernate. hbm2ddl. Auto" Value="Update"/>Write the DDL as a DLL and find that the DDL cannot be automatically generated. Now.
2. Multiple employees correspond to one company.
CompanyCode:
PackageCom. Persia. JPA;ImportJavax. Persistence. entity;ImportJavax. Persistence. ID; @ entityPublic ClassCompany {@ IDPrivate IntID;PrivateString name ;}
Employee code:
PackageCom. Persia. JPA;ImportJavax. Persistence. entity;ImportJavax. Persistence. ID;ImportJavax. Persistence. joincolumn;ImportJavax. Persistence. manytoone; @ entityPublic ClassEmployee {@ IDPrivate IntID;PrivateString name; @ manytoone @ joincolumn (name ="CID")PrivateCompany ;}
3. generated database table
Mysql> DESC company->; + ------- + -------------- + ------ + ----- + --------- + ------- + | FIELD | type | null | key | default | extra | + ------- + -------------- + ------ + ----- + --------- + ------- + | ID | int (11) | no | pri | null | Name | varchar (255) | Yes | null | + ------- + -------------- + ------ + ----- + --------- + ------- + 2 rows in SET (0.00 Sec) mysql> DESC employee; + ------- + -------------- + ------ + ----- + --------- + ------- + | FIELD | type | null | key | default | extra | + ------- + -------------- + ------ + ----- + --------- + ------- + | ID | int (11) | no | pri | null | Name | varchar (255) | Yes | null | CID | int (11) | Yes | Mul | null | +------- + -------------- + ------ + ----- + --------- + ------- + 3 rows in SET (0.00 Sec)