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 view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine-java/-/WFtOxs1dupUJ.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to