/** * @author Oliver Gierke */ @Entity(name = "SampleOrder") @Data public class Order { @Id @GeneratedValue// private Long id; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)// private List<LineItem> items = new ArrayList<>(); @ManyToOne// private Customer customer; public Order add(LineItem item) { this.items.add(item); return this; } }
@MappedSuperclass public abstract class Parent<C extends Child> { @Id @GeneratedValue Long id; @MapKey @OneToMany(mappedBy="parent") Map<Long,C> children = new HashMap<Long,C>(); public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Map<Long,C> getChildren() { return children; } public void setChildren(Map<Long,C> children) { this.children = children; } }
@Entity @Table(name = "PARENT") private static class Parent { @Id @GeneratedValue(strategy = GenerationType.AUTO) Long id; @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) List<Child> children; void setChildren(List<Child> children) { this.children = children; } }
@Entity(name = "BaseTestEntity") @Table(name = "BASE_TEST_ENTITY") public static class BaseTestEntity { @Id @GeneratedValue Long id; @OneToMany Set<TestEntity> entities; }
@Entity @Table( name = "PARENT" ) private static class Parent { @Id @GeneratedValue( strategy = GenerationType.AUTO ) Long id; @OneToMany( mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.LAZY ) List<Child> children; void setChildren(List<Child> children) { this.children = children; } }
@Entity( name = "Branch" ) @Table( name = "BRANCH" ) public static class Branch { @Id @GeneratedValue public Integer id; public String branchName; @OneToMany public List<Leaf> leaves; }
/** * @author Emmanuel Bernard */ @Entity @Table(name = "Bs") public class Customer implements Serializable { @Id @GeneratedValue public Integer id; @OneToMany(mappedBy = "customer") public Set<StoreCustomer> stores; private static final long serialVersionUID = 3818501706063039923L; }
@Entity private static class Author { @Id @GeneratedValue Long id; @OneToMany( fetch = FetchType.LAZY, mappedBy = "author" ) List<ChildItem> items; // keep this field after 'items' String name; }
/** * @author Shawn Clowater */ @Entity @org.hibernate.annotations.Entity( persister = "org.hibernate.persister.entity.SingleTableEntityPersister" ) @Persister( impl = org.hibernate.test.annotations.persister.EntityPersister.class ) public class Deck implements Serializable { @Id public Integer id; @OneToMany( mappedBy = "deck" ) @Persister( impl = org.hibernate.test.annotations.persister.CollectionPersister.class ) public Set<Card> cards; }
@Entity(name = "ParentEntity") @Table(name = "PARENT_ENTITY") public static class ParentEntity { @Id private Long id; @OneToMany @JoinColumn(name = "PARENT") Set<ChildEntity> children; }
@Entity @Table(name = "GEOZONE", schema=SchemaConstant.SALESMANAGER_SCHEMA) @Id @Column(name = "GEOZONE_ID") @TableGenerator(name = "TABLE_GEN", table = "SM_SEQUENCER", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT", pkColumnValue = "GEOZONE_SEQ_NEXT_VAL") @GeneratedValue(strategy = GenerationType.TABLE, generator = "TABLE_GEN") private Long id; @OneToMany(mappedBy = "geoZone", cascade = CascadeType.ALL) private List<GeoZoneDescription> descriptions = new ArrayList<GeoZoneDescription>(); @OneToMany(mappedBy = "geoZone", targetEntity = Country.class) private List<Country> countries = new ArrayList<Country>(); @Column(name = "GEOZONE_NAME") private String name; @Column(name = "GEOZONE_CODE") private String code;