Maybe you also need to set the employee field of the ContactInfo entity with the correct Employee instance before persisting it.
JM On 18 oct, 09:29, Jean-Marc Truillet <[email protected]> wrote: > Hello, > > Why do you set the @Basic annotation though the employee is not a > basic type? > I suggest you to remove it and add "fetch=FetchType.EAGER" to the > @OneToOne annotation, to retrieve the employee and the contact in the > same time. > Personally, I try to avoid bidirectionnal one to one relation. > > Hope it helps. > > JM > > On 17 oct, 21:35, kidowell <[email protected]> wrote: > > > > > Dear All. I need a help here. I may be misunderstanding something. > > > I have 2 classes Employee and ContactInfo. in a bidirectional OneToOne > > relation. Being Employee the owner side. > > > When retrieving an employee the attribute contactInfo is okay, but when I > > retreive a particular contactInfo. The attribute employee is null. > > > Here are the classes: > > > @Entity > > @Table(name = "employee") > > public class Employee implements Serializable { > > > @Id > > @GeneratedValue(strategy = GenerationType.IDENTITY) > > private Long id; > > @Basic > > private String firstName; > > @Basic > > @OneToOne(cascade = CascadeType.ALL) > > private ContactInfo contactInfo; > > > public Employee() { > > super(); > > this.contactInfo = new ContactInfo(); > > } > > > //getters and setters... > > > @Entity > > @Table(name = "contact_info") > > public class ContactInfo implements Serializable { > > > @Id > > @GeneratedValue(strategy = GenerationType.IDENTITY) > > private Key key; > > > private String mobNumber; > > @Basic > > @OneToOne(mappedBy = "contactInfo") > > private Employee employee; > > > public ContactInfo() { > > super(); > > > } > > > //getters and setters > > > //Method to retreive contactInfo By Mobile Number > > > public ContactInfo loadContactInfoByMobNumber(String mobNumber) > > throws NullParameterException, GeneralException { > > entityManager = EMF.get().createEntityManager(); > > List<ContactInfo> list; > > ArrayList<ContactInfo> contactInfos; > > if (mobNumber == null) { > > throw new NullParameterException( > > "Parameter aniId cant be null in method > > loadAnnotationById"); > > } > > try { > > String sql = "SELECT ci FROM ContactInfo ci WHERE > > ci.mobNumber='" > > + mobNumber + "'"; > > list = entityManager.createQuery(sql).getResultList(); > > contactInfos = new ArrayList<ContactInfo>(list); > > } catch (Exception e) { > > throw new GeneralException( > > "Exception in method loadAnnotationById: " + > > e.getMessage()); > > } finally { > > if (entityManager.isOpen()) { > > entityManager.close(); > > } > > } > > > return contactInfos.get(0); --------------------------> this > > object has an attribute employee in null :('. > > } > > > Thenk you very much in advance. > > > Regards. > > > -- > > Kido. -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
