资源描述:
《大框架注解方式( framework annotation methods)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、3大框架注解方式(3frameworkannotationmethods)JPAHibernateannotationReleasedate:12-02-2102:25articlesource:InternetJPAannotation1,@Entity(name="EntityName")Namemustbeoptional,oneofthetablesinthecorrespondingdatabase2,@Table(name=),catalog=","schema="Optional,usuallyusedinconjunctionwith@Entity,canonlybe
2、markedattheentity'sclassdefinition,representingtheentitycorrespondingtothedatabasetableinformationName:isoptional,whichrepresentsthenameofthetable.Bydefault,thenameofthetableisconsistentwiththeentityname,andonlythenameofthetableneedstobespecifiedinthecaseofinconsistencyCatalog:isoptional,whichr
3、epresentsthenameofCatalog,anddefaultstoCatalog("")Schema:isoptional,whichrepresentsthenameofSchema,anddefaultstoSchema("")3,@idMust@iddefinesthepropertythatmapstotheprimarykeyofadatabasetable.AnentitycanonlybemappedtoaprimarykeybeforeanattributeisplacedbeforegetXxxx()4,@GeneratedValue(strategy=
4、GenerationType,generator=")OptionalStrategy:representstheprimarykeygenerationstrategy.Thereare4kindsofAUTO,INDENTITY,SEQUENCE,andTABLE,whichareusedtomaketheORMframeworkautomaticallyselected,AccordingtotheIdentityfieldgeneratedbythedatabase,generatedaccordingtothedatabasetableSequencefield,inord
5、ertogenerateanadditionaltablebasedontheprimarykey,defaulttoAUTOGenerator:representsthenameoftheprimarykeygenerator,whichisusuallyassociatedwiththeORMframework,forexample,HibernatecanspecifytheprimarykeygenerationmethodssuchasUUIDExample:??@Id??@GeneratedValues(strategy=StrategyType.SEQUENCE)???
6、PublicintgetPk(){????Returnpk;????}5,@Basic(fetch=FetchType,optional=true)Optional@Basicrepresentsasimplepropertymappingtothefieldofthedatabasetable.ForthegetXxxx()methodwithoutanyannotation,thedefaultis@BasicFetch:?Representsthereadstrategyofthisattribute,withtwokindsofEAGERandLAZY,whicharemas
7、tercrawlanddelayedloading,respectively.ThedefaultisEAGER.Optional:indicateswhethertheattributeisallowedtobenull,anddefaultstotrueExample:??@Basic(optional=false)???PublicStringgetAddress(){????Returnaddress;????}6,@ColumnOptional@