-
persistence NULLs
working with eclipselink drivers, unable to sucesfully input data into the OneToOne entity relationships..though able to see the one to one relationship in the table view(s). Able to see parent entity's data...any sugestions?
CODE::::::
package PERSISTENCE.OnetoOne;
import javax.persistence.*;
@Entity
public class Customer {
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE)
private Long id;
private String name="JF";
private String personality="unknown";
private String aptitudes="Up in the Air...";
@OneToOne(fetch= FetchType.EAGER)
@JoinColumn(name="address_fk")
private Address1 address1;
Customer(){}
@Entity
@Table(name= "Address Table")
public static class Address1 {
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE)
private Long id;
private String location="JNormandy";
Address1(){this.location="JNormandy";}
}
public static void main(String[] args) {
Customer customer= new Customer();
EntityManagerFactory emf= Persistence.createEntityManagerFactory("chapter03P U");
EntityManager em= emf.createEntityManager();
EntityTransaction tx= em.getTransaction();
tx.begin();
em.persist(customer);
tx.commit();
tx.begin();
em.close();
emf.close();
}
}
-
Re: persistence NULLs
Must add a cascadeTYPE option to the "onetoone" annotation....
@OneToOne(fetch=FetchType.EAGER, cascade=CascadeType.ALL);
.................................................. ............