-
Notifications
You must be signed in to change notification settings - Fork 99
HyperJAXB3 Adding required properties
Laurent Schoelens edited this page May 17, 2024
·
1 revision
You can mark several properties of your class as identifier properties. In this case these properties will build up a composite primary key. Hyperjaxb3 detects declarations of composite primary keys and automatically generates the required identifier class.
Consider the following schema snippet:
<xsd:complexType name="Parent">
<xsd:sequence>
<xsd:element name="children" type="Child" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="pk1" type="xsd:string">
<xsd:annotation><xsd:appinfo><hj:id /></xsd:appinfo></xsd:annotation>
</xsd:attribute>
<xsd:attribute name="pk2" type="xsd:string">
<xsd:annotation><xsd:appinfo><hj:id /></xsd:appinfo</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="parentData" type="xsd:string"/>
</xsd:complexType>
This type declares two id properties (attributes pk1
and pk2
). To map this composite primary key, HJ3 will generate a ParentId
class:
Parent.java
...
@Entity(name = "org.jvnet.hyperjaxb3.ejb.tests.ids.tests.Parent")
@Table(name = "PARENT")
@IdClass(Parent.ParentId.class)
@Inheritance(strategy = InheritanceType.JOINED)
public class Parent implements Equals, HashCode
{
...
@Id
@Column(name = "PK1")
public String getPk1() { ... }
...
@Id
@Column(name = "PK2")
public String getPk2() { ... }
...
public static class ParentId implements Serializable, Equals, HashCode
{
protected String pk1;
protected String pk2;
public String getPk1() { ... }
public void setPk1(String value) { ... }
public String getPk2() { ... }
public void setPk2(String value) { ... }
public boolean equals(Object object) { ... }
public int hashCode() { ... }
}
}
Many thanks to Constantine Kulak who helped with this feature.
Yet to be developed.
- Home
- Migration guide
-
JAXB Maven Plugin
- Quick Start
-
User Guide
- Basic Usage
- Specifying What To Compile
- Referencing Resources in Maven Artifacts
- Using Catalogs
- Using Episodes
- Modular Schema Compilation
- Controlling the Output
- Using JAXB Plugins
- Using a Specific JAXB Version
- Configuring Extension, Validation and XML Security
- IDE Integration
- Miscellaneous
- Configuring Proxies
- Maven Documentation
- Configuration Cheat Sheet
- Common Pitfalls and Problems
-
JAXB2 Basics Plugins
- Using JAXB2 Basics Plugins
- JSR-305 Support
-
JAXB2 Basics Plugins List
- SimpleEquals Plugin
- SimpleHashCode Plugin
- Equals Plugin
- HashCode Plugin
- ToString Plugin
- Copyable Plugin
- Mergeable Plugin
- Inheritance Plugin
- AutoInheritance Plugin
- Wildcard Plugin
- Setters Plugin
- Simplify Plugin
- EnumValue Plugin
- JAXBIndex Plugin
- FixJAXB1058 Plugin
- Commons Lang Plugin
- Default Value Plugin
- Fluent API Plugin
- Namespace Prefix Plugin
- Value Constructor Plugin
- Boolean Getter Plugin
- CamelCase Plugin
- XML ElementWrapper Plugin
- Parent Pointer Plugin
- Property Listener Injector Plugin
- Annox
- JAXB Annotate Plugin
-
HyperJAXB3
- Build System Support
- Customization Guide
- Databases
- Development guide
- Extension guide
- FAQ
- IDE Support
- Java Persistence
- JAXB
- JDK Support
- Project Templates
-
Reference
- Adding vendor-specific annotations
- Features
- Integrating Hyperjaxb3 in builds
- Introduction
- Making schema-derived classes ready for JPA
- Adding required properties
- Applying workarounds for JAXB vs. JPA conflicts
- Enforcing top-level classes
- Generating equals and hashCode methods
- Generating ORM metadata
- Generating persistence unit descriptor
- JPA 2 Support
- Making classes serializable
- Testing generated mappings
- Reference - single page
- Related Projects
- Sample projects
- Solutions
- Target Scenarios
- Test Projects
- Tutorials
- Best Practices
- FAQ
- Sample Projects
- Support
- License
- Distribution