-1
我想獲得另一個ejb的字段值這裏是我的示例我想從類(Visite)中獲取「CLient」的值,並在「ClientVisite 「在類(DateVisite)比在數據庫中堅持這個值。從另一個ejb獲取一個字段的值
這裏是我的代碼
package model.entitie;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.ColumnResult;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import model.entitie.Visite;
@Entity
@NamedQueries({ @NamedQuery(name = "Datevisite.findAll", query = "select o from Datevisite o") })
@SequenceGenerator(name = "DateVisite_Id_Seq_Gen", sequenceName = "DATEVISITE_SEQ", allocationSize = 1,
initialValue = 50)
public class Datevisite implements Serializable {
private static final long serialVersionUID = -341535626783197699L;
@Id
@Column(nullable = false, length = 4000)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "DateVisite_Id_Seq_Gen")
private String iddatevis;
@Temporal(TemporalType.DATE)
private Date jourvisite;
@ManyToOne
@JoinColumn(name = "VISITE_ID")
private Visite datevisite;
@Temporal(TemporalType.DATE)
@Column(name = "JOURVISITEEND")
private Date jourvisteend;
@Column(name = "DESCRPTION")
private String description;
@Column(name = "CLIENTVISITE")
private String ClientVisite;
public void setClientVisite(String ClientVisite) {
this.ClientVisite = ClientVisite;
}
public String getClientVisite() {
return ClientVisite;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public void setJourvisteend(Date jourvisteend) {
this.jourvisteend = this.jourvisite;
}
public Date getJourvisteend() {
return jourvisteend;
}
public Datevisite() {
}
public Datevisite(String iddatevis, Date jourvisite, Visite datevisite, String ClientVisite) {
this.iddatevis = iddatevis;
this.jourvisite = jourvisite;
this.datevisite = datevisite;
this.ClientVisite = ClientVisite;
}
public String getIddatevis() {
return iddatevis;
}
public void setIddatevis(String iddatevis) {
this.iddatevis = iddatevis;
}
public Date getJourvisite() {
return jourvisite;
}
public void setJourvisite(Date jourvisite) {
this.jourvisite = jourvisite;
}
public Visite getDatevisite() {
return datevisite;
}
public void setDatevisite(Visite datevisite) {
this.datevisite = datevisite;
}
}
的介紹瀏覽類
package model.entitie;
import java.io.Serializable;
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.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
@Entity
@NamedQueries({ @NamedQuery(name = "Visite.findAll", query = "select o from Visite o") })
@SequenceGenerator(name = "Visite_Id_Seq_Gen", sequenceName = "VISITE_SEQ", allocationSize = 1, initialValue = 50)
public class Visite implements Serializable {
private static final long serialVersionUID = 2402539910369717472L;
@Column(length = 4000)
public String client;
@Column(length = 4000)
private String dep;
@Id
@Column(nullable = false, length = 4000)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Visite_Id_Seq_Gen")
private String idvisite;
@Column(length = 4000)
private String nbvisites;
@OneToMany(mappedBy = "datevisite", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
private List<Datevisite> datevisiteList;
public Visite() {
}
public Visite(String client, String dep, String idvisite, String nbvisites) {
this.client = client;
this.dep = dep;
this.idvisite = idvisite;
this.nbvisites = nbvisites;
}
public String getClient() {
return client;
}
public void setClient(String client) {
this.client = client;
}
public String getDep() {
return dep;
}
public void setDep(String dep) {
this.dep = dep;
}
public String getIdvisite() {
return idvisite;
}
public void setIdvisite(String idvisite) {
this.idvisite = idvisite;
}
public String getNbvisites() {
return nbvisites;
}
public void setNbvisites(String nbvisites) {
this.nbvisites = nbvisites;
}
public List<Datevisite> getDatevisiteList() {
return datevisiteList;
}
public void setDatevisiteList(List<Datevisite> datevisiteList) {
this.datevisiteList = datevisiteList;
}
public Datevisite addDatevisite(Datevisite datevisite) {
getDatevisiteList().add(datevisite);
datevisite.setDatevisite(this);
return datevisite;
}
public Datevisite removeDatevisite(Datevisite datevisite) {
getDatevisiteList().remove(datevisite);
datevisite.setDatevisite(null);
return datevisite;
}
}
,這是我堅持它
public Datevisite persistDatevisite(Datevisite datevisite) {
datevisite.setJourvisteend(datevisite.getJourvisite());
em.persist(datevisite);
return datevisite;
}
你的意思是另一種「實體」,而不是「EJB」吧? EJB是服務/會話bean。只是爲了澄清。除此之外,你嘗試了什麼?你的問題在哪裏? – Thomas
是的,我的意思是它我試圖公共無效setClientVisite(字符串ClientVisite,Visite visite){ this.ClientVisite = visite.getClient(); }並沒有任何事情發生 – user3419507
除了你有2個參數但只使用一個參數的事實之外,它應該在實體連接時工作。當你設置一個硬編碼的字符串時它工作嗎?必須是同一個地方,否則它可能會在一個地方連接並拆分到另一個地方。 – Thomas