users@glassfish.java.net

Re: Could not persist secondary entity class - enterprise.appclient.MainWithMod

From: <glassfish_at_javadesktop.org>
Date: Fri, 04 Jun 2010 07:26:03 PDT

Hi Tim,

Below is the code snippets for the relevant EJB components:

public class SecurityApplicationClient {
    29 @EJB
    30 private static CustomerRemote customerbean;
    31 private static SecurityRemote securitybean;
    ......
    602 Customer customer = new Customer();
    603 customer.setMembership(A12345);
    604 customer.setFirstname("John");
    605 customer.setSurname("Smith");
    ....
    620 customerbean.createCustomer(customer);

    622 PersonalAccount personalAC = new PersonalAccount();
    623 personalAC.setBankName("Bank of America");
    624 personalAC.setAccountNumber(B67890);
    625 Date date = new Date();
    626 personAC.setDateJoined(date);
    .......
    633 securitybean.createPersonalAccount(personAC);

@Entity
@IdClass(CustomerPK.class)
@Table(name="CUSTOMER", catalog="CustomerDB", schema="")
public class Customer implements Serializable {
    @Id
    @Column(name="NUMBER")
    private String customerNumber;
    public String getMembership() { return customerNumber; }
    public void setMembership(String customerNumber) { this.customerNumber = customerNumber; }
    
    @Id
    @Column(name="FIRSTNAME")
    private String firstname;
    public String getFirstname() { return firstname; }
    public void setFirstname(String firstname) { this.firstname = firstname; }

    @Id
    @Column(name="SURNAME")
    private String surname;
    public String getSurname() { return surname; }
    public void setSurname(String surname) { this.surname = surname; }
    ....
}

@Stateless
public class CustomerBean implements CustomerRemote {
        @PersistenceContext(unitName="SecurityDB-PU") private EntityManager manager;
        public void createCustomer(Customer customer) { manager.persist(customer); }
......
}

@Entity
@Table(name="PERSONAL_ACCOUNT", catalog="SecurityDB", schema="")
public class PersonalAccount implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="ID")
    private int id;
    public void setId(int id) { this.id = id; }
    public int getId() { return id; }

    @Column(name="BANK_NAME")
    private String bankName;
    public String getBankName() { return bankName; }
    public void setBankName(String bankName) { this.bankName = bankName; }
    ......
}

@Stateless
public class PersonalAccountBean implements PersonalAccountRemote {
    
    @PersistenceContext(unitName="SecurityDB-PU") private EntityManager manager;
    
    public void createPersonalAccount(PersonalAccount personalAC)
    {
        manager.persist(personalAC);
    }
.....
}

Thanks,

Jack
[Message sent by forum member 'htran_888']

http://forums.java.net/jive/thread.jspa?messageID=472763