Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
JavaJEEJPA
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=Annotations= The location of the annotations e.g. before the attributes/fields or before the methods is important. #Access to attributes: JPA allows for two types of access to the data of a persistent class, field/property access or method access. What access type it will be used is decided by where you put the @Id annotation (on the id field or the getId() method). Which type to use depends on: performance (reflection is faster?), logic inside the getter and/or setter, validation, independent refactoring, exception handling (see. Java Persistance with Hibernate, 3.25). #Names of the db columns: Field access which means that it maps the instance variables (fields) to columns in the database and Property access which means that is uses the getters to determine the property names that will be mapped to the db. ==javax.persistence.AttributesOverrides== @EmbeddedId @AttributeOverrides( { @AttributeOverride(name = "kategorieId", column = @Column(name = "kategorie_id", nullable = false)), @AttributeOverride(name = "sprachId", column = @Column(name = "sprach_id", nullable = false)) }) Only make sense with the Embedded Annotations to override specifications for the embedded class. ==javax.persistence.Basic== '''@javax.persistence.Basic('''['''fetch='''('''FetchType.EAGER'''|'''FetchType.LAZY''')]''')''' <method declaration> The Basic annotation maps the java type to a database type. It is standard and has to be used seldomly. It can be used to specify the fetch strategy. Normally all attributes are fetched while loading the entity. Lazy delays it to the first use. ==javax.persistence.Column== '''@javax.persistence.Column('''['''name="'''<Name>'''"''']''', [length='''<Number>]) <attribute declaration> The length parameter is important for maximum string length. ==javax.persistence.Entity== '''@javax.persistence.Entity'''['''('''['''name="'''<Name>'''"''']''')'''] * if name is not specified the entity name e.g. used in JPA queries is the classname * if no table specified, tablename is classname * all members are persistent, unless speficied with [[#javax.persistance.Transient|javax.persistence.Transient]] ==java.persistence.GeneratedValue== java.persistence.GeneratedValue([strategy=GenerationType.(AUTO|IDENTITY|SEQUENCE|TABLE)]) * AUTO is the default. The implementation is depending of the type of the ID attribute. For nummeric it is a sequence or table generator. * strategy = GenerationType.IDENTITY means the IDs are not generated in Java code, but instead assigned by the underlying database. It can be used for MySQL database which have an auto increment procedure on id columns ==javax.persistence.Id== Simple ids are mapped using @Id to a single property of one of these types: Java primitive and primitive wrapper types, String, Date, BigDecimal, BigInteger. A primary key: * should never be null * should unique * should never change. See also [[JavaJEEJPA#java.persistence.GeneratedValue|@GeneratedValue annotations]]. ==javax.persistence.Lob== '''@javax.persistence.Lob''' <method declaration> * large object for large data * the concrete type is derived from the java datatype ==javax.persistence.ManyToOne== '''@ManyToOne('''['''fetch =''' <FetchTypes>]''')''' '''@JoinColumn(name = "'''<ColumnName>'''"'''[, '''nullable =''' <Boolean>] [''', updatable =''' true] [''', insertable =''' true]''')''' The @JoinColumn is optional (to specify the column name) according to [https://thorben-janssen.com/ultimate-guide-association-mappings-jpa-hibernate/ here]. ==javax.persistence.MappedSuperClass== * no seperate table ==javax.persistence.OneToMany== '''@javax.persistence.OneToMany'''['''('''['''mappedBy="<AttributName>"'''][''',fetch = FetchType.'''<FetchType>][''',cascade = {'''<CascadeTypes>'''}'''][''',ophanRemoval= '''<Boolean>]''')'''] '''@org.hibernate.annotations.Fetch(FetchMode.SUBSELECT)''' '''@OrderColumn[(name = "'''<column in the table of many side>'''")'''] *'''MappedBy''' attribute names references the name of the attribute in the reference many class. * FetchType '''eager''' loads all referenced objects at once e.g. if the complete object has to be given or send outside the persistence management system. '''Casscade types''' are Cascade.ALL, .... * '''Orphan removal''' = true is important for correct merge. * The '''order column''' is necessary for sorted collections like lists. If no column is specified it will be created by the JPA implementation. ???Unfortunately Hibernate does not correctly interpret these annotations (see [https://hibernate.onjira.com/browse/HHH-5732 here]). The pattern for solving this issues is described [http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-hibspec-collection-extratype-indexbidir here]. The values in the column fields have to be managed by the application. ==javax.persistence.OneToOne== '''@javax.persistence.OneToOne'''['''('''['''cascade = '''<CascadeTypes>][''',fetch = FetchType.'''<FetchType>]''')'''] * default cascade type is empty * default fetch type is EAGER ==javax.persistence.OrderColumn== see [[#javax.persistence.OneToMany|here]] ==javax.persistence.PersistenceContext== works if the client is running inside a persistance provider. '''@javax.persistence.PersistenceContext'''['''('''['''type='''('''TRANSACTION'''|'''EXTENDED''')][''',''']['''unitName="'''<Name>'''"''']''')'''] private javax.persistence.EntityManager <attribute name>; injection via '''@javax.persistence.PersistenceContext(unitName="testejbapplication")''' // s. persistence.xml <persistence-unit> '''private javax.persistence.EntityManager em;''' The annotations can not be used everywhere e.g. using it in the static method of the HibernateUtil class of application [[uweheuer]]. The error is 'the annotation is disallowed at this location'. ==javax.persistance.Table== '''@javax.persistance.Table'''['''('''['''name="'''<Name>'''"''']''')'''] <class declaration> ==javax.persistance.Temporal== '''@javax.persistance.Temporal'''['''(TemporalType.DATE'''|'''TemporalType.TIME'''|'''TemporalType.TIMESTAMP)'''] <method declaration> Specifies the database type for the java type java.util.Date or java.util.Calendar. ==javax.persistance.Transient== * mark fields as not mapped to DB
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width