下面列出了怎么用javax.persistence.ManyToOne的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* @return the inspect action
*/
@ManyToOne
@JoinColumn(name = "inspect_action_id", referencedColumnName = "id", insertable = false,
updatable = false)
public Action getInspectAction() {
return inspectAction;
}
@Override
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "rechnung_fk", nullable = false)
public RechnungDO getRechnung()
{
return rechnung;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected Object unmarshallField(UnmarshallingContext context, Object result, Class type, Field field) {
if (field.getAnnotation(ManyToOne.class) != null) {
Long entityId = (Long) context.convertAnother(context.currentObject(), Long.class);
return AppLoader.getInstance(Dao.class).load((Class<? extends AbstractEntity>) field.getType(), entityId);
} else {
return super.unmarshallField(context, result, type, field);
}
}
/**
* Not used as object due to performance reasons.
* @return
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "task_id", nullable = false)
public TaskDO getTask()
{
return task;
}
/**
* Gets the person detail element.
*
* @return the person detail element
*/
@ManyToOne(targetEntity = PersonDetailElement.class, cascade = {
CascadeType.ALL
})
@JoinColumn(name = "PERSON_DETAIL_ELEMENT_PERSON_0")
public PersonDetailElement getPersonDetailElement() {
return personDetailElement;
}
public static String valueOf(Object object, java.lang.reflect.Field field) throws Exception {
if (field.getType().equals(String.class)) {
return (String ) field.get(object);
}
if (field.getType().equals(Blob.class) && field.get(object) != null) {
return FileExtractor.getText((Blob) field.get(object));
}
Object o = field.get(object);
if (field.isAnnotationPresent(ManyToOne.class) && o instanceof JPABase) {
return "" + getIdValueFor((JPABase ) o);
}
return "" + field.get(object);
}
/**
* Gets the document detail container.
*
* @return the document detail container
*/
@ManyToOne(targetEntity = DocumentDetailContainer.class, cascade = {
CascadeType.ALL
})
@JoinColumn(name = "DOCUMENT_DETAIL_CONTAINER_DO_0")
public DocumentDetailContainer getDocumentDetailContainer() {
return documentDetailContainer;
}
/**
* @return the build action
*/
@ManyToOne
@JoinColumn(name = "build_action_id", referencedColumnName = "id", insertable = false,
updatable = false)
public Action getBuildAction() {
return buildAction;
}
@SuppressWarnings("unchecked")
@Override
public Object findSerializer(Annotated am) {
if (am.hasAnnotation(ManyToOne.class)) {
return new ManyToOneSerializer((Class<AbstractEntity>) am.getRawType());
} else {
return super.findDeserializer(am);
}
}
/** -> Gantt */
@Deprecated
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE}, targetEntity = TaskDO.class)
@JoinColumn(name = "gantt_predecessor_fk")
public TaskDO getGanttPredecessor()
{
return ganttPredecessor;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_role_ci_type", insertable = false, updatable = false)
public AdmRoleCiType getAdmRoleCiType() {
return this.admRoleCiType;
}
/** @return null. */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CONFIG_ID")
public JavamailConfig getJavamailConfig() {
return this.javamailConfig;
}
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
public SequencedAddress getAddress() {
return address;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "contact_id", nullable = false)
public Contact getContact() {
return this.contact;
}
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinColumn(name = "SPECIFICATION_ID")
public Specification getSpecification() {
return specification;
}
/** @return null. */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "USER_BASE_ID")
public UserBase getUserBase() {
return this.userBase;
}
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "schema_id", nullable = false)
public Schema getSchema() {
return schema;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_adm_user")
public AdmUser getAdmUser() {
return this.admUser;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "level", nullable = false)
public Level getLevel() {
return this.level;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "recruitId")
public Recruit getRecruit() {
return recruit;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "AUTHORITY_ID")
public Authority getAuthority() {
return this.authority;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "entity_key", nullable = false)
public BusinessEntity getBusinessEntity() {
return this.businessEntity;
}
/** @return null. */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TYPE_ID")
public WorkcalType getWorkcalType() {
return this.workcalType;
}
@Override
protected MetaAttribute createAttribute(T metaDataObject, PropertyDescriptor desc) {
MetaEntityAttribute attr = new MetaEntityAttribute();
attr.setName(desc.getName());
attr.setParent(metaDataObject, true);
if (hasJpaAnnotations(attr)) {
ManyToMany manyManyAnnotation = attr.getAnnotation(ManyToMany.class);
ManyToOne manyOneAnnotation = attr.getAnnotation(ManyToOne.class);
OneToMany oneManyAnnotation = attr.getAnnotation(OneToMany.class);
OneToOne oneOneAnnotation = attr.getAnnotation(OneToOne.class);
Version versionAnnotation = attr.getAnnotation(Version.class);
ElementCollection elemCollectionAnnotation = attr.getAnnotation(ElementCollection.class);
attr.setVersion(versionAnnotation != null);
FetchType fetchType = null;
if (manyManyAnnotation != null) {
fetchType = manyManyAnnotation.fetch();
}
if (oneManyAnnotation != null) {
fetchType = oneManyAnnotation.fetch();
}
if (oneOneAnnotation != null) {
fetchType = oneOneAnnotation.fetch();
}
attr.setAssociation(manyManyAnnotation != null || manyOneAnnotation != null || oneManyAnnotation != null
|| oneOneAnnotation != null);
boolean lazyCollection = elemCollectionAnnotation != null
&& elemCollectionAnnotation.fetch() != FetchType.EAGER;
boolean lazyAssociation = attr.isAssociation() && (fetchType == null || fetchType == FetchType.LAZY);
attr.setLazy(lazyCollection || lazyAssociation);
} else {
attr.setDerived(true);
}
attr.setSortable(true);
attr.setFilterable(true);
return attr;
}
@JoinColumn(name="movie")
@ManyToOne
public Movie getMovie() {
return movie;
}
/** @return null. */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ACCOUNT_ID")
public AccountInfo getAccountInfo() {
return this.accountInfo;
}
@ManyToOne
@JoinColumn(name="roleId", referencedColumnName = "id")
public Role getRoleId() {
return roleId;
}
@ManyToOne
@JoinColumn(name="cretor",referencedColumnName="id")
public Users getUsers() {
return users;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "topicId", nullable = false)
public CfsTopic getCfsTopic() {
return this.cfsTopic;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "owner_fk")
public PFUserDO getOwner()
{
return owner;
}