by
0
6
2,506
5
Top 1% !
Popular
Famous
Tagged
Specified
OpenSource
Popularity: 6751st place

Published on:

LanguageJava
LicenseMIT_X11

Equipment class - Integration of JPA and JAXB Java classes

The class models an Equipment, referencing its own Network class via ManyToOne and XmlIDREF annotations. It has many Card objects and refers to unique EquipmentController, using annotation OneToOne.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/43632/Equipment-class---Integration-of-JPA-and?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
package com.examples.jpa; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.xml.bind.annotation.*; @XmlType(propOrder = {"id", "network", "label", "cards", "equipmentController"}) @XmlAccessorType(XmlAccessType.FIELD) @Entity @Table(name = "EQUIPMENT") public class Equipment implements Serializable { @XmlElement(name = "equipment-ID") @XmlID @Id @GeneratedValue(strategy = GenerationType.AUTO) private String id; @ManyToOne @XmlIDREF private Network network; @XmlElement(name = "equipment-label") @Column(name = "LABEL", length = 125) private String label; @XmlElementWrapper(name = "cards") @XmlElement(name = "equipment-cards") @OneToMany(mappedBy = "equipment", cascade = CascadeType.ALL, orphanRemoval = true) private List<Card> cards; @XmlElement(name = "equipment-controller") @OneToOne(cascade = CascadeType.ALL) private EquipmentController equipmentController; public Equipment() { } public Equipment(String label) { this.label = label; } public String getId() { return id; } public void setId(String id) { this.id = id; } public void addCard(Card card) { if (cards == null) { this.cards = new ArrayList(); } card.setEquipment(this); cards.add(card); } public List<Card> getCards() { return cards; } public void setCards(List<Card> cards) { this.cards = cards; } public String getLabel() { return label; } public void setLabel(String label) { this.label = label; } public EquipmentController getEquipmentController() { return equipmentController; } public void setEquipmentController(EquipmentController equipmentController) { this.equipmentController = equipmentController; equipmentController.setEquipment(this); } @Override public String toString() { return "Equipment{" + "id=" + id + ", label=" + label + ", equipmentController=" + equipmentController + '}'; } /** * @return the network */ public Network getNetwork() { return network; } /** * @param network the network to set */ public void setNetwork(Network network) { this.network = network; } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus