-2

newMapで詳細を結合する方法custMap

 Map<String, Customer> custMap= new HashMap<String,Customer>();   
 Map<String, DoCustomer> newMap= new HashMap<String,DoCustomer>();
     for (Map.Entry<String, DoCustomer> cust: newMap.entrySet()) {   
     custMap.put(cust.getKey(),cust.getValue()); 
 }

public class DoCustomer {
private Long id;

private String custName;

private String description;
    private String status;
    private List<DoCustomerBranch> doCustomerBranch=new ArrayList<DoCustomerBranch>
public Long getId() {
    return id;
}
public void setId(Long id) {
    this.id = id;
}
public String getCustName() {
    return custName;
}
public void setCustName(String custName) {
    this.custName = custName;
}
public String getDescription() {
    return description;
}
public void setDescription(String description) {
    this.description = description;
}
public String getStatus() {
    return status;
}
public void setStatus(String status) {
    this.status = status;
}
getter/setters of doCustomerBranch
}

  @Entity
  @Table(name = "CUSTOMER")
  public class Customer implements Serializable{

private static final long serialVersionUID = 1L;
private Long id;

private String custName;

private String description;

private String createdBy;
private Date createdOn;

private String updatedBy;
private Date updatedOn;


private Set<CustomerBranch> customerBranch=new HashSet<CustomerBranch>



@Id
@GeneratedValue(generator = "CUSTOMER_SEQ")
@SequenceGenerator(name = "CUSTOMER_SEQ", sequenceName = "CUSTOMERN_SEQ",   allocationSize = 1)
@Column(name = "ID")
public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}


@Column(name = "CUST_NAME",nullable=false)
public String getCustName() {
    return custName;
}

public void setCustName(String custName) {
    this.custName = custName;
}

@Column(name = "DESCRIPTION")
public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}


@Column(name = "CREATED_BY", length = 50)
public String getCreatedBy() {
    return createdBy;
}

public void setCreatedBy(String createdBy) {
    this.createdBy = createdBy;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATED_ON")
public Date getCreatedOn() {
    return createdOn;
}

public void setCreatedOn(Date createdOn) {
    this.createdOn = createdOn;
}

@Column(name = "UPDATED_BY", length = 50)
public String getUpdatedBy() {
    return updatedBy;
}

public void setUpdatedBy(String updatedBy) {
    this.updatedBy = updatedBy;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "UPDATED_ON")
public Date getUpdatedOn() {
    return updatedOn;
}

public void setUpdatedOn(Date updatedOn) {
    this.updatedOn = updatedOn;
}
    @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REMOVE }, fetch =         FetchType.LAZY, mappedBy = "customer")
public Set<CustomerBranch> getCustomerBranch() {
    return customerBranch;
}


public void setCustomerBranch(Set<CustomerBranch> customerBranch) {
    this.customerBranch = customerBranch;
}

 }

顧客支店

@Entity
@Table(name = "CUSTOMER_BRANCH")
public class CustomerBranch implements Serializable{

   @Id
@GeneratedValue(generator = "CUSTOMER_BRANCH_SEQ")
@SequenceGenerator(name = "CUSTOMER_BRANCH_SEQ", sequenceName =   "CUSTOMER_BRANCH_SEQ", allocationSize = 1)
@Column(name = "ID")
private Long id;
private String branchName;

private String branchAddress;

private Customer customer;



public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

@Column(name = "BRANCH_NAME",nullable=false)
public String getBranchName() {
    return branchName;
}



@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MOBEE_CUSTOMER")
public Customer getCustomer() {
    return customer;
}

public void setCustomer(Customer customer) {
    this.customer = customer;
}

    }
4

3 に答える 3

4

DoCustomerコードの問題は、をCustomerコンテナに入れたいということです。DoCustomerがのサブクラスである場合にのみ機能しCustomerます。

編集1:を使用してBeanUtilsをに変換できます。これが良いチュートリアルです。DoCustomerCustomer

于 2012-06-12T07:59:49.317 に答える
3

意味は:

custMap.putAll(newMap)
于 2012-06-12T07:59:06.627 に答える
0

他の誰もが指摘したように、DoCustomer が何を支援できるかを知る必要があります。

しかし、あなたが私たちに与えてくれたものから、各 DoCustomer を Customer にキャストするか、より正確には、各 DoCustomer のフィールドから新しい Customer を作成することをお勧めします。

何かのようなもの:

custMap.put(cust.getKey(), new Customer(cust.getValue().getId(), cust.getValue().getCustName(), and so on..));

あなたのforループの中に。

あなたが提供した定義済みの顧客クラスにはコンストラクターがないことがわかります。そのため、当然、コンストラクターを追加する必要があります

于 2012-06-12T10:04:39.360 に答える