Unable to map two entities in the default user interface

Help
Nirvana
2013-05-30
2013-06-05
  • Nirvana
    Nirvana
    2013-05-30

    Hi Team,

    I've created two entities,
    1) USER_INFO_TBL:
    USER_INFO_ID, - pk
    FIRST_NAME,
    LAST_NAME,
    AGE.

    2) USER_CONTACT_TBL
    USER_CONTACT_ID -pk
    MOBILE_NUMBER
    PRIMARY_EMAIL,
    SECONDARY_EMAIL,
    USER_INFO_ID - fk(USER_INFO_TBL - PK)

    generated the db tables using the build target updateSchema.

    Entity Code :

    class UserInfoTbl :

    @Entity
    @Table(name = "USER_INFO_TBL", schema = "SYSTEM")

    @View(members = "User Personal Details" + "[#" + "firstName, lastName,age; "+"];"
    +"userContactTbls"
    )

    public class UserInfoTbl implements java.io.Serializable {

    private BigDecimal userInfoId;
    private Long age;
    private String firstName;
    private String lastName;
    private Set<UserContactTbl> userContactTbls = new HashSet<UserContactTbl>(0);
    
    public UserInfoTbl() {
    }
    
    public UserInfoTbl(BigDecimal userInfoId) {
        this.userInfoId = userInfoId;
    }
    
    public UserInfoTbl(BigDecimal userInfoId, Long age, String firstName,
            String lastName, Set<UserContactTbl> userContactTbls) {
        this.userInfoId = userInfoId;
        this.age = age;
        this.firstName = firstName;
        this.lastName = lastName;
        this.userContactTbls = userContactTbls;
    }
    
    @Id
    @Column(name = "USER_INFO_ID", unique = true, nullable = false, scale = 0)
    @SequenceGenerator(name = "userInfoSeq", sequenceName = "USER_INFO_SEQ", allocationSize = 1, initialValue = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "userInfoSeq")
    
    public BigDecimal getUserInfoId() {
        return this.userInfoId;
    }
    
    public void setUserInfoId(BigDecimal userInfoId) {
        this.userInfoId = userInfoId;
    }
    
    @Column(name = "AGE", precision = 10, scale = 0)
    public Long getAge() {
        return this.age;
    }
    
    public void setAge(Long age) {
        this.age = age;
    }
    
    @Column(name = "FIRST_NAME", length = 60)
    public String getFirstName() {
        return this.firstName;
    }
    
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    
    @Column(name = "LAST_NAME", length = 60)
    public String getLastName() {
        return this.lastName;
    }
    
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "userInfoTbl")
    public Set<UserContactTbl> getUserContactTbls() {
        return this.userContactTbls;
    }
    
    public void setUserContactTbls(Set<UserContactTbl> userContactTbls) {
        this.userContactTbls = userContactTbls;
    }
    

    }

    UserContactTbl :

    @Entity
    @Table(name = "USER_CONTACT_TBL", schema = "SYSTEM")

    @View(members =
    //"userInfoTbl" +
    "User Contact Details" + "[#" + "mobileNumber, primaryEmail,secondaryEmail; ];"
    )

    public class UserContactTbl implements java.io.Serializable {

    private BigDecimal userContactId;
    private UserInfoTbl userInfoTbl;
    private String mobileNumber;
    private String primaryEmail;
    private String secondaryEmail;
    
    public UserContactTbl() {
    }
    
    public UserContactTbl(BigDecimal userContactId) {
        this.userContactId = userContactId;
    }
    
    public UserContactTbl(BigDecimal userContactId, UserInfoTbl userInfoTbl,
            String mobileNumber, String primaryEmail, String secondaryEmail) {
        this.userContactId = userContactId;
        this.userInfoTbl = userInfoTbl;
        this.mobileNumber = mobileNumber;
        this.primaryEmail = primaryEmail;
        this.secondaryEmail = secondaryEmail;
    }
    
    @Id
    @Column(name = "USER_CONTACT_ID", unique = true, nullable = false, scale = 0)
    @SequenceGenerator(name = "userContactSeq", sequenceName = "USER_CONTACT_SEQ", allocationSize = 1, initialValue = 1 )
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "userContactSeq")
    public BigDecimal getUserContactId() {
        return this.userContactId;
    }
    
    public void setUserContactId(BigDecimal userContactId) {
        this.userContactId = userContactId;
    }
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "USER_INFO_ID")
    public UserInfoTbl getUserInfoTbl() {
        return this.userInfoTbl;
    }
    
    public void setUserInfoTbl(UserInfoTbl userInfoTbl) {
        this.userInfoTbl = userInfoTbl;
    }
    
    @Column(name = "MOBILE_NUMBER", length = 44)
    public String getMobileNumber() {
        return this.mobileNumber;
    }
    
    public void setMobileNumber(String mobileNumber) {
        this.mobileNumber = mobileNumber;
    }
    
    @Column(name = "PRIMARY_EMAIL", length = 80)
    public String getPrimaryEmail() {
        return this.primaryEmail;
    }
    
    public void setPrimaryEmail(String primaryEmail) {
        this.primaryEmail = primaryEmail;
    }
    
    @Column(name = "SECONDARY_EMAIL", length = 80)
    public String getSecondaryEmail() {
        return this.secondaryEmail;
    }
    
    public void setSecondaryEmail(String secondaryEmail) {
        this.secondaryEmail = secondaryEmail;
    }
    

    }

    The issue is after deploying the code : I can't see all the two entity fields in single interface - i can access each interface with two url (with different entites)

    Example : http://localhost:8181/EntityRelationship/modules/UserInfoTbl
    http://localhost:8181/EntityRelationship/modules/UserContactTbl

    Since both the tables are dependent (pk-fk relationship) , do we have any chance of getting both of them in single Interface.

    note : all the CRUD operations are working fine(individually).

    Do we have any chance of getting all the fields in same Interface (with 2 different dependent relationship), Is there anything did I miss out in the entity source code.

    Can anyone please please help me on this.

    Thanks in advance.

    Regards,
    Nirvana

     
  • Hi Nirvana,

    I have updated a bit your code and it show User and Contacts on the same page.
    This is easy to be made with OpenXava.

    please try the code below:

    package bg.d3soft.openxava.demo.user;
    
    import java.io.*;
    import java.math.*;
    import javax.persistence.*;
    import org.openxava.annotations.*;
    
    @Entity
    @Table(name = "USER_CONTACT_TBL")//, schema = "SYSTEM"
    @View(members = "#mobileNumber, primaryEmail, secondaryEmail;")
    public class UserContact implements Serializable {
    
        private static final long serialVersionUID = 1L;
    
        private BigDecimal id;
        private UserInfo userInfo;
        private String mobileNumber;
        private String primaryEmail;
        private String secondaryEmail;
    
        public UserContact() {
        }
    
        public UserContact(BigDecimal userContactId) {
            this.id = userContactId;
        }
    
        public UserContact(BigDecimal userContactId, UserInfo userInfoTbl,
                String mobileNumber, String primaryEmail, String secondaryEmail) {
            this.id = userContactId;
            this.userInfo = userInfoTbl;
            this.mobileNumber = mobileNumber;
            this.primaryEmail = primaryEmail;
            this.secondaryEmail = secondaryEmail;
        }
    
        @Id
        @Column(name = "USER_CONTACT_ID", unique = true, nullable = false, scale = 0)
        @SequenceGenerator(name = "userContactSeq", sequenceName = "USER_CONTACT_SEQ", allocationSize = 1, initialValue = 1)
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "userContactSeq")
        public BigDecimal getId() {
            return this.id;
        }
    
        public void setId(BigDecimal userContactId) {
            this.id = userContactId;
        }
    
        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "USER_INFO_ID")
        public UserInfo getUserInfo() {
            return this.userInfo;
        }
    
        public void setUserInfo(UserInfo userInfoTbl) {
            this.userInfo = userInfoTbl;
        }
    
        @Column(name = "MOBILE_NUMBER", length = 44)
        public String getMobileNumber() {
            return this.mobileNumber;
        }
    
        public void setMobileNumber(String mobileNumber) {
            this.mobileNumber = mobileNumber;
        }
    
        @Column(name = "PRIMARY_EMAIL", length = 80)
        public String getPrimaryEmail() {
            return this.primaryEmail;
        }
    
        public void setPrimaryEmail(String primaryEmail) {
            this.primaryEmail = primaryEmail;
        }
    
        @Column(name = "SECONDARY_EMAIL", length = 80)
        public String getSecondaryEmail() {
            return this.secondaryEmail;
        }
    
        public void setSecondaryEmail(String secondaryEmail) {
            this.secondaryEmail = secondaryEmail;
        }
    }
    
    package bg.d3soft.openxava.demo.user;
    
    import java.io.*;
    import java.math.*;
    import java.util.*;
    import javax.persistence.*;
    import org.openxava.annotations.View;
    
    @Entity
    @Table(name = "USER_INFO_TBL")//, schema = "SYSTEM"
    @View(members = "#firstName, lastName, age;"
            + "userContacts"
    )
    public class UserInfo implements Serializable {
    
        private static final long serialVersionUID = 1L;
    
        private BigDecimal id;
        private Long age;
        private String firstName;
        private String lastName;
        private Set<UserContact> userContacts = new HashSet<UserContact>(0);
    
        public UserInfo() {
        }
    
        public UserInfo(BigDecimal userInfoId) {
            this.id = userInfoId;
        }
    
        public UserInfo(BigDecimal userInfoId, Long age
                , String firstName, String lastName
                , Set<UserContact> userContactTbls) 
        {
            this.id = userInfoId;
            this.age = age;
            this.firstName = firstName;
            this.lastName = lastName;
            this.userContacts = userContactTbls;
        }
    
        @Id
        @Column(name = "USER_INFO_ID", unique = true, nullable = false, scale = 0)
        @SequenceGenerator(name = "userInfoSeq", sequenceName = "USER_INFO_SEQ", allocationSize = 1, initialValue = 1)
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "userInfoSeq")
        public BigDecimal getId() {
            return id;
        }
    
        public void setId(BigDecimal userInfoId) {
            this.id = userInfoId;
        }
    
        @Column(name = "AGE", precision = 10, scale = 0)
        public Long getAge() {
            return this.age;
        }
    
        public void setAge(Long age) {
            this.age = age;
        }
    
        @Column(name = "FIRST_NAME", length = 60)
        public String getFirstName() {
            return this.firstName;
        }
    
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
    
        @Column(name = "LAST_NAME", length = 60)
        public String getLastName() {
            return this.lastName;
        }
    
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
    
        @OneToMany(fetch = FetchType.LAZY, mappedBy = "userInfo")
        public Set<UserContact> getUserContacts() {
            return this.userContacts;
        }
    
        public void setUserContacts(Set<UserContact> userContacts) {
            this.userContacts = userContacts;
        }
    }
    
     
    • Nirvana
      Nirvana
      2013-06-03

      Hi Trifon,

      Thanks for the response.
      1) First thing is unable to run the target updateSchema : ORA-02261: such unique or primary key already exists in the table, So removed the 'unque=true', and then able to go forward.

      2) As per your change I see the both the entities in one interface, but UserContact is in a block with all the CRUD buttons again.
      3) None of the CRUD operations works, when I'm saving it says 'Impossible to create: an object with that key already exists' I don't know why. In the DB table there is an insert with all column as null except the PK.

      With default CRUD opertions :
      Can I insert the data in single steps in two tables.
      Can I read the data in single steps from two tables and display in same page.

      Problem is I'm very new to OpenXava, I need to migrate(starting from scratch) my existing project with OPenXava.

      So I need a very huge help with these kind 0f problems, since I have a huge table dependencies(almost 10-15 tables) .

      Thanks in advance.

      Regards,
      Nirvana.

       
      Last edit: Nirvana 2013-06-03
      • Hi Nirvana,

        2) As per your change I see the both the entities in one interface, but
        UserContact is in a block with all the CRUD buttons again.

        I do not understand if this is question.
        Can you please describe in details what you want to achieve?

        With default CRUD opertions :

        >Can I insert the data in single steps in two tables.
        >Can I read the data in single steps from two tables and display in same
        page.

        You must do two steps:
        1) Create parent record: In your case User.
        2) Create child record in your UserContact.

        You can add records into two different tables from only one OpenXava screen.
        Please have a look at OpenXava demo.

        Regards,
        Trifon

        2013/6/3 Nirvana nirvanam@users.sf.net

        Hi Trifon,

        Thanks for the response.
        1) First thing is unable to run the target updateSchema : ORA-02261: such
        unique or primary key already exists in the table, So removed the
        'unque=true', and then able to go forward.

        2) As per your change I see the both the entities in one interface, but
        UserContact is in a block with all the CRUD buttons again.
        3) None of the CRUD operations works, when I'm saving it says 'Impossible
        to create: an object with that key already exists' I don't know why. In the
        DB table there an insert with all nulls except the PK.

        With default CRUD opertions :
        Can I insert the data in single steps in two tables.
        Can I read the data in single steps from two tables and display in same
        page.

        Problem is I'm very new to OpenXava, I need to migrate(starting from
        scratch) my existing project with OPenXava.

        So I need a very huge help with these kind 0f problems, since I have a
        huge table dependencies(almost 10-15 tables) .

        Thanks in advance.

        Regards,
        Nirvana.


        Unable to map two entities in the default user interfacehttps://sourceforge.net/p/openxava/discussion/419690/thread/0dcf6dc7/?limit=25#e962/b790

        Sent from sourceforge.net because you indicated interest in
        https://sourceforge.net/p/openxava/discussion/419690/

        To unsubscribe from further messages, please visit
        https://sourceforge.net/auth/subscriptions/

         
  • 2) As per your change I see the both the entities in one interface, but UserContact is in a block with all the CRUD buttons again.

    I do not understand if this is question.
    Can you please describe in details what you want to achieve?

    With default CRUD opertions :
    Can I insert the data in single steps in two tables.
    Can I read the data in single steps from two tables and display in same page.

    You must do two steps:
    1) Create parent record: In your case User.
    2) Create child record in your UserContact.

    You can add records into two different tables from only one OpenXava screen.
    Please have a look at OpenXava demo.

     
    • Nirvana
      Nirvana
      2013-06-03

      Hi Trifon,

      Thanks for the quick response.

      You must do two steps:
      1) Create parent record: In your case User.
      2) Create child record in your UserContact.

      This is as general as doing from a DB client(with quires).

      My problem is one single save should insert both in user_info and user_contact tables.(This is requirement we have from the client).

      Example : User Interface should almost look like a single entity, including all CRUD Operations (because of the requirement).

      I'm so particular because of the requirement.

      Regards,
      Nirvana

       
    • Nirvana
      Nirvana
      2013-06-04

      Hi Trifon,

      Any suggestions ?

      Regards,
      Nirvana

       
  • Hi Nirvana,

    My problem is one single save should insert both in user_info and user_contact tables.(This is requirement we have from the client).

    This is easy.
    You just need to change java class UserInfo and add cacade=CascadeType.REMOVE

        @OneToMany(mappedBy = "userInfo", fetch = FetchType.LAZY,  cascade=CascadeType.REMOVE)
        public Set<UserContact> getUserContacts() {
            return this.userContacts;
        }
    

    Below is the full class:
    package bg.d3soft.openxava.demo.user;

    import java.io.;
    import java.math.
    ;
    import java.util.;
    import javax.persistence.
    ;

    import org.openxava.annotations.*;

    @Entity
    @Table(name = "USER_INFO_TBL")//, schema = "SYSTEM"
    @View(members = "#firstName, lastName, age;"
    + "userContacts"
    )
    public class UserInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    private BigDecimal id;
    private Long age;
    private String firstName;
    private String lastName;
    private Set<UserContact> userContacts = new HashSet<UserContact>(0);

    public UserInfo() {
    }

    public UserInfo(BigDecimal id) {
    this.id = id;
    }

    public UserInfo(BigDecimal id, Long age
    , String firstName, String lastName
    , Set<UserContact> userContactTbls)
    {
    this.id = id;
    this.age = age;
    this.firstName = firstName;
    this.lastName = lastName;
    this.userContacts = userContactTbls;
    }

    @Id
    @Column(name = "USER_INFO_ID", unique = true, nullable = false, scale = 0)
    @SequenceGenerator(name = "userInfoSeq", sequenceName = "USER_INFO_SEQ", allocationSize = 1, initialValue = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "userInfoSeq")
    public BigDecimal getId() {
    return id;
    }

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

    @Column(name = "AGE", precision = 10, scale = 0)
    public Long getAge() {
    return this.age;
    }

    public void setAge(Long age) {
    this.age = age;
    }

    @Column(name = "FIRST_NAME", length = 60)
    @DisplaySize(value=20)
    public String getFirstName() {
    return this.firstName;
    }

    public void setFirstName(String firstName) {
    this.firstName = firstName;
    }

    @Column(name = "LAST_NAME", length = 60)
    @DisplaySize(value=20)
    public String getLastName() {
    return this.lastName;
    }

    public void setLastName(String lastName) {
    this.lastName = lastName;
    }

    @OneToMany(mappedBy = "userInfo", fetch = FetchType.LAZY, cascade=CascadeType.REMOVE)
    public Set<UserContact> getUserContacts() {
    return this.userContacts;
    }

    public void setUserContacts(Set<UserContact> userContacts) {
    this.userContacts = userContacts;
    }
    }

    Regards,
    Trifon