public class JpaHelper extends Object
entities (based on
EntityManager). In some cases it is required to access JPA features in a static way. E.g. a
common case is a setter in your entity for a
reference from an
ETO that can be achieved via the following code:
@Entity
@Table("Foo")
public class FooEntity extends ApplicationPersistenceEntity implements Foo {
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "bar")
private BarEntity bar;
...
@Override
public void setBarId(IdRef <Bar> barId) {
this.bar = JpaHelper.asEntity(barId, BarEntity.class);
}
}
| Constructor and Description |
|---|
JpaHelper() |
| Modifier and Type | Method and Description |
|---|---|
static <E extends GenericEntity<?>,P extends E> |
asEntities(Collection<? extends E> input,
Class<P> entityClass,
Collection<P> output) |
static <E> E |
asEntity(Ref<?,? super E> reference,
Class<E> entityClass) |
public static <E extends GenericEntity<?>,P extends E> void asEntities(Collection<? extends E> input, Class<P> entityClass, Collection<P> output)
E - generic type of the input entities (most commonly the entity interface).P - generic type of the output entities.input - the Collection of entities (e.g.
ETOs) to use as input.entityClass - the Class reflecting the entity.output - die Collection where to add the entities
corresponding to the input entities. Most probably empty
but may also already contain entities so this method will add additional entities.Copyright © 2014–2019 devon4j-Team. All rights reserved.