[Ref] http://xdoclet.sourceforge.net/xdoclet/tags/hibernate-tags.html http://www.hibernate.org/5.html
Available in two ways:
1. Primary key association
[Main]: one-to-one
[From]: one-to-one constrained = "true" name = "@ PP"
Master key ID: generator-class = "foreign" generator-param name = "prot" value = "@ pp"
2. The only foreign key association
[Main]: Many-to-one unique = "true" name = "@ P1"
[From]: One-to-one property-ref = "@ p1" (no two-way can omit this property)
.
Station (must have a getDetail property)
/ ** * Modify STATIONDETAIL ID generated policy to foreign * @ hibernate.one-to-one cascade = "all" * / public stationdetail getdetail () {return detail;}
STATIONDETAIL (must have a getStation property)
/ ** * @Hibernate Property = "ID" * @ hibernate.id * column = "* unsaved-value =" - 1 "* generator-class =" foreign "* @ hibernate.generator-param name =" Property "value =" station "station is the attribute of the foregoing * / public long getId () {return ID;}
/ ** * constrained = "true" means using this property as the primary key * @ hibernate.one-to-one constrained = "true" name = "station" * @Return * / public station getstation () {return station;}
SQL
create table t_station_detail (id bigint not null, address text, email varchar (255), fax varchar (255), introduce text, tel varchar (255), primary key (id)) create table t_station (id bigint not null auto_increment, code varchar (10), name varchar (255), primary key (id)) alter table t_station_detail add index FKEADD08E7D1B (id), add constraint FKEADD08E7D1B foreign key (id) references t_station (id) 2. Station 1--1 StationDetail Station. Station_detail is stored as stationdetail.id
Station
/ ** * Modify STATIONDETAIL ID Generation Policy to Foreign * @ hibernate.many-to-one name = "detil" column = "station_detail" cascade = "all" unique = "true" * / public stationdetail getdetail () {Return Detail;
STATIONDETAIL
ID generation uses native, if you don't need a two-way association, you can do not need.
/ ** * constrained = "true" means using this property as the primary key * @ hibernate.one-to-one constrained = "false" Property-Ref = "detail" * @return * / public station getstation () {Return Station; }
SQL
Create Table T_Station_Detail (ID Bigint Not Null Auto_Increment, Address Text, Email Varchar (255), Fax Varchar (255), Introduce Text, Tel Varchar (255), Primary Key (ID))
Create Table T_Station (ID Bigint Not Null Auto_Increment, Code Varint Unique, Name Varchar (255), Primary Key (ID))
ALTER TABLE T_STATION Add Index FK4A7DF4695C5811BC (station_detail), add constraint fk4a7df4695c5811bc foreign key (station_detail) References T_Station_Detail (ID)