Unidirectional one-to-many relationship without a join table

Hello,
I have 2 classes, Invoice and InvoiceLine, and a one-to-many unidirectional relationship from Invoice to InvoiceLine. By default, with JPA, it would be mapped by a join table with foreign keys that refer to the 2 tables which represent Invoice and InvoiceLine.
My problem: the database has already a foreign key in the table which represents InvoiceLine that refers to the table which represents Invoice.
To solve my problem I could make the relationship bidirectional but I would like to know if it is possible to keep it unidirectional and to use the foreign key which already exists (in the table that represents InvoiceLine). How could I declare the mapping with JPA?
Thanks in avance for your answers.

JPA requires that any @OneToMany mapping not using a join table have an inverse @ManyToOne mapping. In general the foreign key in the target object needs to be mapped and a @ManyToOne mapping is normally the best way to map it, so making the relationship bi-directional is your best option.
There are other ways in TopLink to map a unidirectional 1-m, but these are not directly supported by the JPA spec. You could define a TopLink OneToManyMapping for the relationship through a TopLink DescriptorCustomizer and the code API. You would still need to map the foreign key in the target object some way, but you could use a @Basic mapping for this as long as you keep it in synch.
In TopLink you could also map the relationship using an AggregateCollectionMapping (basically a collection of embeddables), and then not require mapping the foreign key in the target, but this imposes limitations on the target object (must be treated like an embeddable instead of entity). You would also need to configure the target object to be an aggregateCollectionDescriptor if using this option.

Similar Messages

  • One-to-Many implemented with a join Table

    Hello,
    Is it possible to implement a One-to-Many relationship with a join table, just like
    the Reference Implementation does.
    Regards,
    Jeroen

    "Jeroen Ferdinandus" <[email protected]> wrote in
    news:[email protected]:
    Is it possible to implement a One-to-Many relationship with a join
    table, just like the Reference Implementation does.Not with our CMP, you will have to resort to BMP for that.
    Cedric

  • One-to-many relationship: problem with several tables on the one side...

    Hello
    I'm having problems developing a database for a content management system. Apart from details, I've got one main table, that holds the tree structure of the content ("resources") and several other tables that contain data of a particular datatype ("documents", "images", etc.). Now, there's one-to-many relationship between "resources" table and all the datatype tables - that is, in the "resources" table there's "resource_id" column, being a foreign key referenced to the "id" columns in the datatype tables.
    The problem is that this design is deficient. I can't tell form the "resource_id" column from which datatype table to get the data. It seems to me that one-to-many relationship only works with two tables. If the data on the one side of the relationship is contained in several tables, problems arise.
    Anybody knows a solution? I would be obliged.
    Regards
    Havocado

    Hi;
    A simple way may be create a view on referenced tables:
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL>
    SQL> drop table resources;
    Table dropped
    SQL> create table resources(id number, name varchar2(12));
    Table created
    SQL> insert into resources values(1,'Doc....');
    1 row inserted
    SQL> insert into resources values(2,'Img....');
    1 row inserted
    SQL> drop table documents;
    Table dropped
    SQL> create table documents(id number, resource_id number,type varchar2(12));
    Table created
    SQL> insert into documents values(1,1,'txt');
    1 row inserted
    SQL> drop table images;
    Table dropped
    SQL> create table images(id number, resource_id number,path varchar2(24));
    Table created
    SQL> insert into images values(1,2,'/data01/images/img01.jpg');
    1 row inserted
    SQL> create or replace view vw_resource_ref as
      2    select id, resource_id, type, null as path from documents
      3      union
      4     select id, resource_id, null as type, path from images;
    View created
    SQL> select * from resources r inner join vw_resource_ref rv on r.id = rv.resource_id;
            ID NAME                 ID RESOURCE_ID TYPE         PATH
             1 Doc....               1           1 txt         
             2 Img....               1           2              /data01/images/img01.jpg
    SQL> Regards....

  • Unidirectional one-to-many with join table

    According to http://docs.jboss.org/hibernate/orm/3.5/reference/en-US/html/associations.html#assoc-unidirectional-12m "A unidirectional one-to-many association on a foreign key is an unusual case, and is not recommended", instead they recommend using a join table, e.g.
    create table Person ( personId bigint not null primary key )
    create table PersonAddress ( personId not null, addressId bigint not null primary key )
    create table Address ( addressId bigint not null primary key )
    However if doing this, when using SQLDeveloper the Address table does not appear as a child table of Person, which it should be as a unidirectional one-to-many meaning that I can't create a cache group for Person and subsequently Person.
    Is this something that can be worked around as I'm using a legacy schema created from Hibernate/JPA and the implications of changing are quite substantial?
    Thanks

    Hi Gennady,
    Apologies but my question was not clear enough. The schema structure that I have inherited is as follows:
    CREATE TABLE T_PERSON ( PERSONID NUMBER PRIMARY KEY, PERSONFIRSTNAME VARCHAR2(20), PERSONLASTNAME VARCHAR2(20) );
    CREATE TABLE T_PERSONADDRESS (PERSONID NUMBER NOT NULL, ADDRESSID NUMBER NOT NULL PRIMARY KEY );
    CREATE TABLE T_ADDRESS ( ADDRESSID NUMBER  PRIMARY KEY, ADDRESSTEXT VARCHAR2(200) );
    ALTER TABLE T_PERSONADDRESS ADD CONSTRAINT FK_PERSON_ADDR_PERSON_ID FOREIGN KEY (PERSONID) REFERENCES T_PERSON(PERSONID);
    ALTER TABLE T_PERSONADDRESS ADD CONSTRAINT FK_PERSON_ADDR_ADDR_ID FOREIGN KEY (ADDRESSID) REFERENCES T_ADDRESS(ADDRESSID);This is implementing a unidirectional one-to-many relationship between T_PERSON and T_ADDRESS according to the Hibernate and JPA recommendation. As far as I can see most schema designers would do this using by adding a column "PERSON_ID" (and associated FK) on the T_ADDRESS table and therefore not needing the T_PERSONADDRESS table.
    This being what it is, I would then like to create a cache-group as follows:
    CREATE READONLY CACHE GROUP "CACHEGROUPADDRESSES"
    AUTOREFRESH MODE INCREMENTAL INTERVAL 5 MINUTES
    STATE PAUSED
    FROM
      "SCHEMA1"."T_PERSON" (
        "PERSONID"        NUMBER            NOT NULL,
        "PERSONFIRSTNAME" VARCHAR2(20 BYTE),
        "PERSONLASTNAME"  VARCHAR2(20 BYTE),
        PRIMARY KEY("PERSONID")
      "SCHEMA1"."T_ADDRESS" (
        "ADDRESSID" NUMBER NOT NULL,
        "ADDRESSTEXT" VARCHAR2(20 BYTE),
        PRIMARY KEY("ADDRESSID")
      "SCHEMA1"."T_PERSONADDRESS" (
        "PERSONID"  NUMBER NOT NULL,
        "ADDRESSID" NUMBER NOT NULL,
        PRIMARY KEY("ADDRESSID"),
        FOREIGN KEY("PERSONID")
          REFERENCES "SCHEMA1"."T_PERSON"("PERSONID"),
        FOREIGN KEY("ADDRESSID")
          REFERENCES "SCHEMA1"."T_ADDRESS"("ADDRESSID")
      )This however gives me the error "TT8222: Multiple parent tables found" because TimesTen has failed to identify the one-to-many-using-link-table pattern.
    Without a schema re-write is there anything that I can do, alternatively will this be looked at for a future release of TimesTen?
    Edited by: TrisStev on Apr 16, 2012 10:37 AM

  • How do I create a One to many relationship page in Dreamweaver?

    How do I create a page in dreamweaver that comes up after the user logs in from the log in page that will allow the user to:
    Add, change and delete in 2 tables that are in my MYSQL database that is a one to many relationship
    One thing that is confusing is how the foreign key that links to the one side of the relationship is created in the many side without the user inputting the foreign key each time adding information to the many side table.
    I am creating this in Dreamweaver using a MYSQL database and PHP.

    >Would the following be a part of it:
    >
    >Outer join
    Probably not. When updating/inserting/deleting from 2 tables you perform each seperately. Table updates may join two or more tables to resolve the correct row(s) but you still only update one table at a time. Procedurally you would create a transaction, update the first table, update the second table and then commit the transaction.
    EDIT: Well I take back my last comment. I see that MySQL does seem to support multiple table updates. I don't use MySQL so I can't really help you on that but the MySQL manual gives pretty clear syntax.

  • One to many relationship leads to recursion?

    Hi,
    I've created a web services function which returns an object retrieved from a database using the persistence api (the class was generated by the Netbeans 5.5 "Entity Class from Database" feature.
    I can successfully return an object which has no foreign keys. However, when I try to retrieve an entity which is on either side of a 1:N relationship, I receive a stackOverflowError.
    Here's my sample schema (I'm using Derby bundled with SJAS 9 for testing)
    create table Address (
       Id int not null,
       StreetName varchar(255),
       City varchar(255),
       PostalCode varchar(255),
       Party int,
       primary key (Id)
    create table Party (
       Id int,
       Name varchar(255),
       primary key(Id)
    alter table Address add constraint foreign key (Party) references Party;So as you can see, one Party might have many addresses.
    I can retrieve either an Address or Party from the database using something like:
    em.createNamedQuery("Party.findById")
       .setParameter("id", 1)
       .getSingleResult();When I try to return it, I get a stackOverflowError in the server log. I'm using the default Toplink provider so enabling full logging on this, I can see the SQL.
    When retrieving an address, it selects all of the address fields and correctly binds the supplied Id value. It then performs a select on the Party table using the Address.Party value. This in turn causes it to attempt to retrieve an Address. After three queries, the error is thrown.
    I can't see why the above schema should cause this problem. Where an Address is requested, I would expect it to retrieve the address fields, including the value of the Party field but not the Party object itself. On the other hand. when a Party is retrieved, I would expect it to recurse through and return a collection of Address objects.
    Have I misunderstood this or am I missing some fundamental point about JAX-WS?
    Thanks for your help,
    -Phil

    You have to set both sides of the relations...
    for example to do this in a more seamless manner:
    public UserProfile
         public void addLog (UserActivityLog activity)
              logs.add (activity);
              if (!equals (activity.getUserProfile ()))
                   activity.setUserProfile (this);
    Now this is the most primitive of ways to maintain two sided relations.
    There are a lot of other patterns to get around this.
    If you want to set the UserActivityLog to a specific UserProfile without
    having a firm reference to ther UserProfile, you should get the object
    from the database/persistenceManager... as you are using application
    identity, you can do something like pm.getObjectById.
    JDO does not do magic references. If you set something to null, it will
    remain null until you set it.
    Srini wrote:
    Hi Guys
    I am trying to create a one to many relationship between 2 JDOs.
    UserProfile - User JDO having user info
    UserActivityLog - JDO having user log info
    UserProfile -- UserActivityLog
    1 many
    UserProfile - has a collection of UserActivityLog objects
    UserActivityLog - has a reference to UserProfile
    Qn 1:
    I created a UserProfile along with a collection of 2 UserActivityLog
    objects.
    Navigation:
    Now given a UserProfile object,i am able to get the UserActivityLog objects.
    But given a UserActivityLog object ,i get a NULL UserProfile object.
    Issues:
    Why this is happening???Do i need to set the reference for "UserProfile" in
    UserActivityLog before inserting???
    If so,then how do i add a UserActivityLog to an existing
    UserProfile???cos,if i create a UserActivityLog with reference to
    UserProfile ,then it will throw a Duplicate Key violation for UserProfile as
    it is already persisted in DB.
    It will be great if you can direct me to some one to many relationship
    examples already implemented.
    Thanks
    Srini
    Stephen Kim
    [email protected]
    SolarMetric, Inc.
    http://www.solarmetric.com

  • One to many relationships in EJB

    I have two EBs related by a one to many relationship. The first of these tables is called Student and has studentId as its key. The second of the tables has a composite key made up of studentID, courseID and semesterID.
    However, when the tables are generated in NetBeans 5.5, I find that the Course table has studentID as both a primary key and a foreign key.
    I am at a loss to understand this as I am new to NetBeans and EJB.
    Can anyone advise?
    Thanks
    Martin O'Shea.
    The Student class:
    package CBSD_CW;
    import java.io.Serializable;
    import javax.persistence.*;
    import java.util.*;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    @Entity
    public class Student_EB implements Serializable {
        // Table columns.
        @Id
        @Column(name = "STUDENT_ID", nullable = false)
        private Long studentId; // Student ID. Entity <Student><ID> from file: SampleData.xml.
        @Column(name = "FIRST_NAME", length = 50, nullable = true)
        private String firstName; // First Name. Entity <Student><FirstName> from file: SampleData.xml.
        @Column(name = "LAST_NAME", length = 50, nullable = true)
        private String lastName; // Last Name. Entity <Student><LastName> from file: SampleData.xml.
        @Column(name = "STUDENT_LEVEL", length = 2, nullable = true)
        private String studentLevel; // Student Level. Entity <Student><Level> from file: SampleData.xml.
        @Column(name = "PROGRAM_NAME", length = 50, nullable = true)
        private String programName; // Program Name. Entity <Student><ProgramName> from file: SampleData.xml.
        @Column(name = "PROGRAM_NUMBER", length = 3, nullable = true)
        private String programNumber; // Program Number. Entity <Student><ProgramNumber> from file: SampleData.xml.
        // 1:M relationship with Course_EB.
        @OneToMany(cascade=CascadeType.ALL, mappedBy="student")
        private List<Course_EB> courses;
        public List<Course_EB> getCourses() {
           return courses;
        public void setCourses(List<Course_EB> courses) {
           this.courses = courses;
        // Accessors and mutators.
        public Long getId() {
            return this.studentId;
        public void setId(Long studentId) {
            this.studentId = studentId;
        public String getFirstName() {
            return firstName;
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        public String getLastName() {
            return lastName;
        public void setLastName(String lastName) {
            this.lastName = lastName;
        public String getStudentLevel() {
            return studentLevel;
        public void setStudentLevel(String studentLevel) {
            this.studentLevel = studentLevel;
        public String getProgramName() {
            return programName;
        public void setProgramName(String programName) {
            this.programName = programName;
        public String getProgramNumber() {
            return programNumber;
        public void setProgramNumber(String programNumber) {
            this.programNumber = programNumber;
        // Other methods.
        public boolean equals(Object obj) {
           if (obj == this) {
               return (true);
           if (!(obj instanceof Student_EB)) {
               return (false);
           if (obj == null) {
               return (false);
           Student_EB student = (Student_EB) obj;
           return (student.studentId == studentId);
    The Course class:
    package CBSD_CW;
    import javax.persistence.CascadeType;
    import javax.persistence.EmbeddedId;
    import javax.persistence.Entity;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinTable;
    import javax.persistence.ManyToOne;
    @Entity
    public class Course_EB implements java.io.Serializable {
       Course_PK course;
       // M:1 relationship with Student_EB.
       private Student_EB student;
       @ManyToOne(cascade=CascadeType.ALL)
       @JoinTable(name = "Student_EB", joinColumns= @JoinColumn(name = "STUDENT_ID", referencedColumnName = "studentId"))
       public Student_EB getStudent() {
          return (student);
       public void setStudent(Student_EB student) {
          this.student = student;
       // Constructor.
       public Course_EB() {
       // Accessors and mutators.
       @EmbeddedId
       public Course_PK  getCourse_PK () {
          return (course);
       public void setCourse_PK(Course_PK course) {
          this.course = course;
    The Course_PK class:
    package CBSD_CW;
    import javax.persistence.Column;
    import javax.persistence.Embeddable;
    @Embeddable
    public class Course_PK implements java.io.Serializable {
       // Table columns.
       @Column(name = "STUDENT_ID", length = 4, nullable = false)
       private long studentId; // Student ID. Entity <Student><ID> from file: SampleData.xml.
       @Column(name = "COURSE_ID", length = 4, nullable = false) 
       private String courseId; // Course ID. Entity <Student><Course><Number> from file: SampleData.xml.
       @Column(name = "SEMESTER_CODE", length = 3, nullable = false)
       private String semesterCode; // Semester Code. Entity <Student><Course><SemesterCode> from file: SampleData.xml.
       @Column(name = "GRADE", nullable = true)
       private char grade; // Grade. Entity <Student><Course><Grade> from file: SampleData.xml.
       // Constructors.
       public Course_PK() {
       public Course_PK(long studentId, long courseid, String semesterCode) {
          this.studentId = studentId;
          this.courseId = courseId;
          this.semesterCode = semesterCode;
       // Accessors and mutators.
       public long getStudentId() {
          return (studentId);
       public void setStudentId(long studentId) {
          this.studentId = studentId;
       public String getCourseId() {
           return (courseId);
       public void setId(String courseId) {
           this.courseId = courseId;
       public String getSemesterCode() {
           return (semesterCode);
       public void setSemesterCode(String semesterCode) {
           this.semesterCode = semesterCode;
       public char getGrade() {
           return (grade);
       public void setGrade(char grade) {
           this.grade = grade;
       // Other methods.
       public boolean equals(Object obj) {
           if (obj == this) {
               return (true);
           if (!(obj instanceof Course_PK)) {
               return (false);
           if (obj == null) {
               return (false);
           Course_PK course = (Course_PK) obj;
           return ((course.studentId == studentId) &&
                   (course.courseId.equals(courseId)) &&
                   (course.semesterCode.equals(semesterCode)) &&
                   (course.grade == grade));
    }

    Because you have field
    @Column(name = "STUDENT_ID", length = 4, nullable = false)
       private long studentId; // Student ID. Entity <Student><ID> from file: SampleData.xml.In you Course_PK class. As a primary keys.
    An again you are joining it in field
        @ManyToOne(cascade=CascadeType.ALL)
       @JoinTable(name = "Student_EB", joinColumns= @JoinColumn(name = "STUDENT_ID", referencedColumnName = "studentId"))So it is appearing both inPrimary Key and in Foreign Key.

  • One to many relationship question.

    Let's say we have table1 and table2
    Table1 has ID, and let's say Name for fields.
    Table2 has ID, and let's say SSN for fields.
    This is not so, but illustrates my points well.
    Table2 has many records with the same ID, who just happen to have the same SSN. That would usually be a logical conclusion.
    Table1 has only 1 of each ID in it. So you might say that ID is a foreign key in table2, except one problem. I don't think they know what primary keys are here, much less foreign keys.
    Anyway, I have to write a query where I get the ID from table1 and need the SSN from table2. That's the only place in this scenario that SSN is.
    My question is this - since this is a one to many relationship, yet I only need 1 result, how would I write this using the (+) way of notation? I am using 8i.
    Right now, I am doing something like this, using a DISTINCT:
    Select DISTINCT t1.ID, t1.Name, t2.SSN
    From table1, table2,
    Where t1.ID = t2.ID (+);
    First of all, is this the correct way of writing it?
    And second, I am wondering if, perchance for some error, there were 2 or more SSNs in table2, what would happen then? Would I get a too many rows error?
    And if so, how can I trap it and possibly get just the first occurrence of it?
    Is that even a sound way of doing it?
    Thanks for any thoughts here.

    You would need to turn your table2 into an in-line view in order to outer join to it properly. Minimally, something like:
    SELECT t1.id, t1.name, t2.ssn
    FROM table1 t1,
         (SELECT DISTINCT id, ssn
          FROM table2) t2
    WHERE t1.id = t2.id(+)If there may be multiple ssn in t2 for a single id, you will need to determine which one you want to keep and use something like:
    SELECT t1.id, t1.name, t2.ssn
    FROM table1 t1,
         (SELECT id, ssn
          FROM (SELECT id, ssn,
                       ROW_NUMBER() OVER (PARTITION BY id,
                                          ORDER BY column_that_makes_it_first) rn
                FROM table2)
          WHERE rn = 1) t2
    WHERE t1.id = t2.id(+)This should work on 8.1.7.4 Enterprise Edition. If you have a different version, then the analytic function may not work so you would need something more like:
    SELECT t1.id, t1.name, t2.ssn
    FROM table1 t1,
         (SELECT id, ssn
          FROM (SELECT id, ssn, rownum rn
                FROM (SELECT id, ssn,
                      FROM table2
                      ORDER BY id, column_that_makes_it_first))
          WHERE rn = 1) t2HTH
    John

  • Persisting an instance of the many side of a in one to many relationship

    It seems as if most books only tell you how to setup the relationship for a one to many relationship but seems to fail to tell you the appropriate way to persist in this relationship. So, I have a parent class with many child classes. Also, I am using services and so I am converting from Entities to Dtos and visa versa.
    First, i want to insert a new child for the parent. Do I just convert the child Dto to a child entity and then persist the child entity with the reference to the parent? Then do I find the parent and add the child to the parents children so the entities are consistent?
    Or do I do a find on the parent and add the child to the parents children list and the child. Will the child be persisted automatically?
    With this said, what about updating a child? Do I remove the existing child and add a new one? or do I somehow find the child in the parents children set and update the info there and then somehow the child is persisted automatically? And since I am using Dto to entity, do I use a find to find the parent and then iterate through that parents children til I reach the child I modified by id somehow.
    What about Many to Many relationships? With a middle join table? How does JPA know to remove a join if I change the child reference? Does it remove the old and insert the new? Or do I have to do it myself somehow. Which if the later then I really can not have a parent child Dto I really need a parent childlink table where the child is referenced by the linktable? The book I have been reading has not made this very clear.

    Hello,
    The relationships cascade settings determine what should happen. I would not recommend persisting a new entity that references a non-managed entity. Instead either persist the child then make the associations or find the parent, make the associations then persist the child. In the second case, you do not need to explicietly persist the child if the parent->child relationship is marked cascade persist, since it will be found on flush or commit.
    Since you are using DTOs, updates require you merge the changes. You can directly merge the child, and if it has a link to its parent, modify the parent to add the child on the managed child that gets returned.
    As for ManyToMany, you must modify the side that controls the relationship. So if the parent owns it, then you must modify or merge the changes into the parent for the changes to be persisted to the database. If it is bi-directional, you must modify both sides so that the cache remains consistent with the database. This should be transparent to your application, and you only need an entity for the relation table if you want to map more complex information that doesn't fit into the JPA ManyToMany options. Otherwise, JPA should handle inserting and deleting enteries to the relation table for you.
    Best Regards,
    Chris

  • How Can realize a one-to-many relationship via RIA service in lightswitch

    I have to query a large data and the normal query in lightswitch is so slow that I decided to use RIA service to improve the query.However I am not very good at RIA service. I follow
    this tutorial and set up a very simple RIA service. In my project, I have a one-to-many relationship but I don't know how to
    realize it . here is the Relationship:
    public class CombinedStadium
    private EcoStatus _ecoStatus;
    [Key]
    public int Id { get; set; }
    public string Name { get; set; }
    public string Category { get; set; }
    public string Owner { get; set; }
    public string Street { get; set; }
    public string OrgCode { get; set; }
    public string Place { get; set; }
    public int? FoundYear { get; set; }
    public double? LandArea { get; set; }
    public double? BuildingArea { get; set; }
    public double? SiteArea { get; set; }
    public double? Investment { get; set; }
    public double? Fiscal { get; set; }
    public double? CommonWeal { get; set; }
    public double? SelfRaised { get; set; }
    public double? SocialDonate { get; set; }
    public double? Other { get; set; }
    public double? Longitude { get; set; }
    public double? Latitude { get; set; }
    public string Note { get; set; }
    public byte[] Photo { get; set; }
    [Include]
    [Association("Stadium_EcoStatus", "Id", "EcoId", IsForeignKey = false)]
    public virtual EcoStatus EcoStatus
    get { return this._ecoStatus; }
    set
    this._ecoStatus = value;
    if (value == null)
    this.Id = value.Id;
    I am not sure whether it is right or not. But I want "one CombinedStadium Entity may contains
    more than one(many)EcoStatus Entities.
    I tried the code above and update my datasource, I got the error "the entity
    LightSwitchApplication.Implementation.EcoStatus's property doesn't supported by the type of StadiumEcoReference".
    How Can I realize a one-to-many relationship via RIA and use it in my lightswitch program?
    thx !!!

    namespace WCF_RIA_Project
    public class CombinedStadium
    [Key]
    public int SiteId { get; set; }
    public string Name { get; set; }
    public string Category { get; set; }
    public string Owner { get; set; }
    public string Street { get; set; }
    public string OrgCode { get; set; }
    public string Place { get; set; }
    public int? FoundYear { get; set; }
    public double? LandArea { get; set; }
    public double? BuildingArea { get; set; }
    public double? SiteArea { get; set; }
    public double? Investment { get; set; }
    public double? Fiscal { get; set; }
    public double? CommonWeal { get; set; }
    public double? SelfRaised { get; set; }
    public double? SocialDonate { get; set; }
    public double? Other { get; set; }
    public double? Longitude { get; set; }
    public double? Latitude { get; set; }
    public string Note { get; set; }
    public byte[] Photo { get; set; }
    [Include]
    [Association("Stadium_EcoStatus", "SiteId", "StadiumId")]
    public IQueryable<CombindeEcoStatus> EcoStatus { get; set; }
    public class CombindeEcoStatus
    [Key]
    public int EcoId { get; set; }
    public string StatdiumName { get; set; }
    public int? StadiumId { get; set; }
    public int? Year { get; set; }
    public int? EmployeeNum { get; set; }
    public string OperateMode { get; set; }
    public string OpenStatus { get; set; }
    public double? OpeningDays { get; set; }
    public string ClientCount { get; set; }
    public double? Income { get; set; }
    public double? Expend { get; set; }
    [Include]
    [Association("Stadium_EcoStatus", "StadiumId", "SiteId", IsForeignKey = true)]
    public CombinedStadium Stadium
    get;
    set;
    public class WCF_RIA_Service : DomainService
    private ApplicationData m_context;
    public ApplicationData Context
    get
    if (this.m_context == null)
    string connString =
    System.Web.Configuration.WebConfigurationManager
    .ConnectionStrings["_IntrinsicData"].ConnectionString;
    EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder();
    builder.Metadata =
    "res://*/ApplicationData.csdl|res://*/ApplicationData.ssdl|res://*/ApplicationData.msl";
    builder.Provider =
    "System.Data.SqlClient";
    builder.ProviderConnectionString = connString;
    this.m_context = new ApplicationData(builder.ConnectionString);
    return this.m_context;
    [Query(IsDefault = true)]
    public IQueryable<CombinedStadium> GetAllStadiums()
    var stadiumsQuery = from stadium in this.Context.StadiumSet
    select new
    ID = stadium.Id,
    Name = stadium.Name,
    Category = stadium.Category.Name,
    OwnerParts = stadium.Owner2StadiumMediatorCollection.Select(x => x.Owner.Name),
    Street = stadium.Street.Name,
    OrgCode = stadium.StadiumBase.OrgCode,
    Place = stadium.StadiumBase.Place,
    FoundYear = stadium.StadiumBase.FoundYear,
    LandArea = stadium.StadiumBase.LandArea,
    BuildingArea = stadium.StadiumBase.BuildingArea,
    SiteArea = stadium.StadiumBase.SiteArea,
    Investment = stadium.StadiumBase.Investment,
    Fiscal = stadium.StadiumBase.Fiscal,
    CommonWeal = stadium.StadiumBase.CommonWeal,
    SelfRaised = stadium.StadiumBase.SelfRaised,
    SocialDonate = stadium.StadiumBase.SocialDonate,
    Other = stadium.StadiumBase.Other,
    Longitude = stadium.StadiumBase.Longitude,
    Latitude = stadium.StadiumBase.Latitude,
    Note = stadium.StadiumBase.Note,
    Photo = stadium.StadiumBase.Photo,
    var result = stadiumsQuery.AsEnumerable().Select(x => new CombinedStadium()
    SiteId = x.ID,
    Name = x.Name,
    Category = x.Category,
    Owner = string.Join("/", x.OwnerParts),
    Street = x.Street,
    OrgCode = x.OrgCode,
    Place = x.Place,
    FoundYear = x.FoundYear,
    LandArea = x.LandArea,
    BuildingArea = x.BuildingArea,
    SiteArea = x.SiteArea,
    Investment = x.Investment,
    Fiscal = x.Fiscal,
    CommonWeal = x.CommonWeal,
    SelfRaised = x.SelfRaised,
    Other = x.Other,
    Longitude = x.Longitude,
    Latitude = x.Latitude,
    Note = x.Note,
    Photo = x.Photo,
    }).AsQueryable();
    return result;
    [Query(IsDefault = true)]
    public IQueryable<CombindeEcoStatus> GetAllEcoStatuses()
    var stadiumEco = from eco in this.Context.EcoStatusSet
    select new CombindeEcoStatus()
    EcoId = eco.Id,
    StatdiumName = eco.StadiumEco.Name,
    StadiumId = eco.StadiumEco.Id,
    Year = eco.Year,
    EmployeeNum = eco.Employee,
    OperateMode = eco.OperateMode,
    OpenStatus = eco.OpenStatus,
    OpeningDays = eco.OpeningDays,
    ClientCount = eco.ClientCount,
    Income = eco.Income,
    Expend = eco.Expend
    return stadiumEco;
    protected override int Count<T>(IQueryable<T> queryable)
    return queryable.Count();
    now I have solved my problem, but when I query the data in Lihgtswitch HTMLClient . I can't get the related entities "CombindeEcoStatus" . How can I write the return value of
    GetAllStadiums function to get the related CombindeEcoStatus of each
    CombinedStadium?
    thanks!

  • Merge Two Reports in Excel Analyzer - One To Many Relationship

    I want to show AR Data with CO Data - e.g. a bill + Income and it's associated account ssignemnt on the FI/CO side. I want the report to be able to show a cost centre manager to be wary of the income credited to their cost centre when a debtor has been raisedaas they may not fully pay the bill. To do this I'm using the standard DSO for AR & GL line items. Fisrtly I run a query on GL line item data where the user can select from a cost centre variable to look at credits to their cost centre. This produces a list of source documents that are used (via replacement path variable) in a second query. The second GL Query gives me a list of the allocation numbers for those line items. Had to be two queres as there are two GL postings that needed linking (this is because the cost assignment comes from a ceratin acc type and the debtor information comes from another acc type). I then use the allocation number (again via a replacement path variable) to run a third query on the AR data that shows all bills and payments linked to that allocation number. It seems to work ok.
    However I have put these three queries in an Excel Analyzer workbook. All the user does is enter a cost centre when running the report. Each query is on a different sheet but what I'd like to do is merge the data on to the one sheet. I want to see the bill and it's payments from the AR data matched up with the cost assignment from the FI/CO data. This would be a one to many relationship e.g. one bill may have it's cost assignment split over more than one cost centre. Is there anyway to do this using simple excel functionality?
    So I'd like to see:
    Allocation No. 12345 Bill £100 Revenue £50 Cost Centre 1234 £25
                                                                           Cost Centre 2345 £25
    Anybody any ideas?

    Hi,
    Thanks for your answers.
    I did explore using infosets but really struggled with joining the data and getting a sensible output. For example where a bill was done in installments I was getting 12 lines (e.g. one for each month) rather than just one. THis meant it looked liked they'd paid twleve times as much etc.
    I did also try report to report. Which to my mind worked ok. Except the customer wanted it all in "One" report rather than having to drill down to see data.
    I'll try a multiprovider but I'm worried that I'll end up with similar issues as I had when using the infoset.
    Cheers
    Joel

  • Techniques to eliminate ripple loading in one to many relationships

    Hi,
    In my domain model, I have a class O that has a one to many relationship with class M. The relationship is mapped in TOPLink as a one to many from O to M, and a one to one from M to O.
    An end user logs into our application that has an otherwise cold TOPLink cache and executes a use case that will render several to many aspects of each O instance, and there are many O instances to render a majority of the time.
    The first time a question is asked of an O instance that requires its M instances to answer the question, TOPLink will detect the unstubbing of that ValueHolder, and cause a SQL query to pull in the necessary M instances for that O instance.
    One technique to combat this ripple load is to mark the relationship between O and M to "useBatchReading". I am motivated to attempt a different technique in the particular scenario I am experiencing though.
    Another technique would seem to be to fetch all of the M instances for all of the O instances to be rendered, compute the relevant Collection of M instances for each O instance and then call mValueHolder.setValue(readCollectionOfMs) on each O instance. Is this technique feasible? Seems like it doesn't align with the intent of the TOPLink API.
    Are there any other techniques that can be used to solve this issue as well?
    Thanks,
    Doug

    Doug,
    What I believe you want is join and batch reading configured on the queries of your specific use case. That gives you much finer control then configuring these on the mappings.
    With TopLink you should have your use cases issue a fixed quantity of SQL statements irrelevant of the # of objects returned from the root query.
    Have you taken a look at the performance tuning chapter in the documentation?
    I hope this helps,
    Doug

  • SELECT on One to many Relationship

    Hi am trying to run a select statement  on one to many relationship.
    TableA is the main table with acount number and Total_Payments
    TableB,TableC and TableD have  a lot of account number and payments
    per day
    Note an account might on TableA might not be on TableB or TableC since it was not paid for that day hence 'if it is Null i'll like to populate a zero.
    OUTPUT should be :
                                      TableA.Account_No | Total_Amount(amounts from TableB/C/D)
    Regards.

    Hello,
    Please refer to the following statements. If I have any misunderstand, please post the DDL of the tables and sample data for further analysis:
    SELECT A.account, SUM(ISNULL(B.payment,0)+ISNULL(C.payment,0)+ISNULL(D.payment,0)) As Total_Amounts
    FROM TableA A LEFT JOIN TableB B ON A.account=B.account
    LEFT JOIN TableC C ON A.account=C.account
    LEFT JOIN TableD D ON A.account=D.account
    GROUP BY A.Account
    Regards,
    Fanny Liu
    If you have any feedback on our support, please click here. 
    Fanny Liu
    TechNet Community Support

  • ONE-to-MANY relationship between tables and forms in APEX

    I recently started using APEX and I have run into an issue.
    I have a ONE-TO-MANY relationship between two tables, A1 and A2, respectively.
    A1:
    A1_ID
    Item
    A2:
    A2_ID
    SubItem
    A1_ID
    I have 2 forms (lets call it F1 and F2) that I use to capture data for A1 and A2.
    On F2, I have the following fields that are setup to capture data:
         A2.A1_ID
    **A1.Item (this is a drop down that is populated using a SELECT statement where the select uses A1.Item field)
         A2.SubItem (user would enter SubItem)
    Note: A2.A2_ID is populated using a SEQ
    Everytime I pick **A1.Item on F2, is there a way to link to A1 table and display A1.A1_ID for every **A1.Item selected on F2?
    If so, I want to store the value captured in F2 for the A1_ID field into A2 table to maintain my 1-to-MANY relationship.
    If this will work, how do I go about implementing this solution?
    Can someone help me?

    I think it sounds like you are asking for a Master-Detail form. Try that and see what you get.
    chris.

  • Urgent : java bean having bidirectional one to many relationship

    Hi,
    We have complex requirement in our application.
    We need to copy java bean having bidirectional one to many relationship to another javabean having bidirectional one to many relationship..
    E.g
    Class Basket1 {
    public String color;
    pubic String type;
    public List<Basket1> basketList = new ArrayList()
    Class Basket2 {
    public String color;
    pubic String type;
    public List<Basket2> basketList = new ArrayList()
    We need to exact copy Basket1 to Basket2. We are in trouble to copy List of child because we do not have how many child Basket1 have of same type..
    Can someone help us how we can implement such kind of complex object bidirectional one to many relationship??

    I can't see anything bidirectional about these relationships. What I can see is a couple of BasketN classes that look identical so I don't know why they both exist, and they both contain lists of themselves as members, which suggests some kind of tree structure. Nothing bidirectional there. I can see tat these things can form circular object graphs but I don't see why you would want to do that.
    We need to exact copy Basket1 to Basket2And I don't know what that means. Please explain.

Maybe you are looking for

  • Font Problems Upgrading from LC 7.2 Forms to ES Update 1 (8.2)

    Old Environment:  LC 7.2 Forms, Windows 2003, Weblogic 8.1 SP5, Oracle 10.2.0.4 Old Fonts Directory:  c:\windows\fonts.  The customer fonts were also added to this directory and the fonts were embedded into the adobe-FontManager.ear. New Environment:

  • Removal of deletion indicator in Production order

    Hi, Can any one explain me how to remove the deletion indicator in production order. thanks and regards Murugesan

  • Problems with the Xserver Bus error

    I think this problem started when I updated to 10.4.10, but I'm not entirely sure. All of the sudden, I lost the Windows Login, the first problem I found was that the "crashreport" couldn't write on file and exited with signal 1 and 10. Following up

  • Windows Jumping In and Out Intermittently

    Every few days my open windows begin doing an exposé dance swinging left and doing a dosy doe (sic). Whatever I do during these episodes doesn't stop it including rebooting. After a while everything calms down and goes away for a while. I turned off

  • Can't create kext cache message

    I get multiples of this message: com.apple.kextd[10] Can't create kext cache under / - owner not root. Just curious as everything works OK.