SET One to many Relationship in MSSQL

How can i set one to many relationship in TABLE ?

Just curious, Why did you add Name here below?
CONSTRAINT PK_Student PRIMARY KEY CLUSTERED
EnrolNo, Name
Try the below:
INSERT INTO Student (EnrolNo, Name, ClassID) VALUES
(3256, 'Sara1', 1)

Similar Messages

  • Possible Bug? Different behaviour for List and Set one-to-many mappings on deletePersistent()

    Hi,
    I have a PC class that represents a TreeNode object (a GcGroup), which
    has a one-to-many relationship with itself to keep track of its descendants.
    For example a hierarchy of A -> B -> C, where A has B,C as descendants
    and B has C as a descendant. This is tracked by adding or removing a
    descendant with a recursive method to update a TreeNode's parent's
    descendants when a child is added or removed.
    The odd behaviour happens when I delete a child and try to remove the
    child manually from all my parent's descendant relations when I use a
    HashSet (possibly happens with any Set). In this case kodo will remove
    the relations with the following SQL statement:
    DELETE FROM TREENODE_DESCENDANTSX JDOIDX = xxxx;
    So when I do my recursive call I get a JDOException thrown stating that
    the object xxxx has already been deleted.
    When I change the relationship to an ArrayList this exception is not
    thrown and I do not get the error.
    Looking at the SQL generated they look the same:
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    27106317
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    28819334
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    10817575
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:21
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    UPDATE GCGroup SET JDOLOCKX=8, child_count=0 WHERE (id = 81 AND JDOLOCKX
    = 7)
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    27106317
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    8331873
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    10817575
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:21
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    DELETE FROM GROUP__DESCENDANTSX WHERE JDOIDX = 12300
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    27106317
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    8331873
    2002-10-31 20:21:42,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    10817575
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:21
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    DELETE FROM GROUP__USERSX WHERE group_id = 12300
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    27106317
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    8331873
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    10817575
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:21
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    DELETE FROM GCGroup WHERE id = 12300
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    27106317
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    10817575
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:21
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:21:42,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    commit data store transaction
    My methods look like the following:
    public void removeChild(TreeNode t) {
         _children.remove(t);
         removeDescendant(t);
    protected void removeDescendant(TreeNode t) {
         if (_parent != null) {
              _parent.removeDescendant(t);
         _descendants.remove(t);
    The following is the stack trace from the exception when using a HashSet:
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    18799851
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    30836962
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29139395
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:54
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    UPDATE GCGroup SET JDOLOCKX=3, child_count=0 WHERE (id = 12450 AND
    JDOLOCKX = 2)
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    18799851
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    28630940
    2002-10-31 20:54:10,046 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29139395
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:54
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    UPDATE GCGroup SET JDOLOCKX=41 WHERE (id = 2 AND JDOLOCKX = 40)
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    18799851
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29663640
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29139395
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:54
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:54:10,062 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    DELETE FROM GROUP__DESCENDANTSX WHERE JDOIDX = 12451
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    18799851
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29663640
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29139395
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:54
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    DELETE FROM GROUP__USERSX WHERE group_id = 12451
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    18799851
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29663640
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29139395
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:54
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:54:10,078 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    DELETE FROM GCGroup WHERE id = 12451
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    18799851
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    5057297
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29139395
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:54
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    DELETE FROM GROUP__DESCENDANTSX WHERE JDOIDX = 12452
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    18799851
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    5057297
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29139395
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:54
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    DELETE FROM GROUP__USERSX WHERE group_id = 12452
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    18799851
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    5057297
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29139395
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:54
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:54:10,093 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    DELETE FROM GCGroup WHERE id = 12452
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    18799851
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29139395
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:54
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    roll back data store transaction
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    18799851
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    4629956
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29139395
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:54
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:54:10,109 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    SELECT t0.id, t0.JDOLOCKX, t0.child_count, t0.description,
    t0.global_read, t0.global_write, t0.name, t0.owner_id, t0.parent_id,
    t0.rank, t0.root_id, t0.user_count, t0.user_exists, t0.visibility FROM
    GCGroup t0 WHERE t0.id = 12451
    2002-10-31 20:54:10,125 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] [ C:
    2002-10-31 20:54:10,125 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    18799851
    2002-10-31 20:54:10,125 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; S:
    2002-10-31 20:54:10,125 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    2951648
    2002-10-31 20:54:10,125 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; T:
    2002-10-31 20:54:10,125 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    29139395
    2002-10-31 20:54:10,125 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ; D:
    2002-10-31 20:54:10,125 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    02/10/31 20:54
    2002-10-31 20:54:10,125 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] ]
    2002-10-31 20:54:10,125 INFO
    [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo]
    SELECT t0.id, t0.JDOLOCKX, t0.child_count, t0.description,
    t0.global_read, t0.global_write, t0.name, t0.owner_id, t0.parent_id,
    t0.rank, t0.root_id, t0.user_count, t0.user_exists, t0.visibility FROM
    GCGroup t0 WHERE t0.id = 12452
    2002-10-31 20:54:10,140 INFO [STDOUT]
    com.gulfnet.common.actions.GroupAction : The exception is:
    javax.jdo.JDOException
    2002-10-31 20:54:10,140 INFO [org.jboss.web.localhost.Engine] action:
    com.gulfnet.common.actions.GroupAction : The exception is:
    javax.jdo.JDOException
    2002-10-31 20:54:10,140 INFO [STDOUT]
    com.gulfnet.common.actions.GroupAction : java.lang.NullPointerException
    2002-10-31 20:54:10,140 INFO [org.jboss.web.localhost.Engine] action:
    com.gulfnet.common.actions.GroupAction : java.lang.NullPointerException
    2002-10-31 20:54:10,140 ERROR [STDERR] javax.jdo.JDOException:
    java.lang.NullPointerException
    NestedThrowables:
    java.lang.NullPointerException
    2002-10-31 20:54:10,156 ERROR [STDERR] at
    com.solarmetric.kodo.ee.EEPersistenceManager.rollback(EEPersistenceManager.java:169)
    2002-10-31 20:54:10,156 ERROR [STDERR] at
    com.gulfnet.usermanager.UserManager.deleteGroup(UserManager.java:775)
    2002-10-31 20:54:10,156 ERROR [STDERR] at
    com.gulfnet.common.actions.GroupAction.deleteObject(GroupAction.java:146)
    2002-10-31 20:54:10,171 ERROR [STDERR] at
    com.gulfnet.common.actions.GroupAction.doAction(GroupAction.java:58)
    Kam

    Forgot to add that I am using SQLServer 2000, Jboss 3.0.3 and Kodo 2.3.4
    Kam

  • How to change the fetch size for a one-to-many relationship

    With Toplink 10.1.3, since using scrollablecursor is a prerequisites for changing the fetchsize on a query (using the setFetchSize), I am wondering if it would be possible to change the fetchsize of the query which is associated to a one-to-many relationship.
    So, is this possible? How ?

    In TopLink 10.1.3 you can set the fetch-size on any query, it has nothing to do with using a ScrollableCursor.
    Example:
    readQuery.setFetchSize(100);
    To set the fetch size on a mapping query use,
    mapping.getSelectionQuery().setFetchSize(100);
    In 10.1.3 you can only set this in code, not currently through XML or the Mapping Workbench. In 10.1.3.1 you should be able to set the value through XML as well.

  • Newbie: one to many relationship SQL error

    Greetings all-
    This is probably a slam dunk for you JDO experts. I'm a JDO newbie, working
    with an existing schema in MySQL. I have a one to many relationship between
    two tables:
    Table "company":
    Fields:
    company_id: int(11) -- primary key
    name : varchar(64)
    division : varchar(64)
    Table "company_products"
    Fields:
    company_id: int(11) -- foreign key to table company
    product_name: varchar(64)
    product_description: varchar(64)
    So, I created the corresponding classes:
    public class Company {
    private int companyID;
    private String company_name;
    private String division;
    // Array of CompanyProduct
    private ArrayList companyProducts;
    // .. methods omitted
    public class CompanyProduct {
    private int companyID;
    private String productName;
    private String productDesc;
    // Methods omitted
    Then I created the "package.jdo" file:
    <?xml version="1.0"?>
    <jdo>
    <package name="com.packexpo.db">
    <class name="Company">
    <extension vendor-name="tt" key="table" value="company"/>
    <extension vendor-name="tt" key="pk-column" value="company_id"/>
    <extension vendor-name="tt" key="lock-column" value="none"/>
    <extension vendor-name="tt" key="class-column" value="none"/>
    <field name="companyID">
    <extension vendor-name="tt" key="data-column" value="company_id"/>
    </field>
    <field name="name">
    <extension vendor-name="tt" key="data-column" value="name"/>
    <extension vendor-name="tt" key="column-length" value="64"/>
    </field>
    <field name="division">
    <extension vendor-name="tt" key="data-column" value="division"/>
    <extension vendor-name="tt" key="column-length" value="64"/>
    </field>
    <field name="companyProducts">
    <collection element-type="com.packexpo.db.CompanyProduct"/>
    <extension vendor-name="tt" key="inverse" value="companyID"/>
    </field>
    </class>
    <class name="CompanyProduct">
    <extension vendor-name="tt" key="table" value="company_product"/>
    <extension vendor-name="tt" key="pk-column" value="company_id"/>
    <extension vendor-name="tt" key="lock-column" value="none"/>
    <extension vendor-name="tt" key="class-column" value="none"/>
    <field name="companyID">
    <extension vendor-name="tt" key="data-column" value="company_id"/>
    </field>
    <field name="productName">
    <extension vendor-name="tt" key="data-column" value="product_name"/>
    <extension vendor-name="tt" key="column-length" value="64"/>
    </field>
    <field name="productDesc">
    <extension vendor-name="tt" key="data-column"
    value="product_description"/>
    <extension vendor-name="tt" key="column-length" value="64"/>
    </field>
    </class>
    </package>
    </jdo>
    Enhancement works fine. I successfully query and retrive Company objects
    from the database, but as soon as I try to get the list of CompanyProducts,
    I get an SQL Error:
    javax.jdo.JDODataStoreException: [SQL=SELECT company.COMPANYPRODUCTSX FROM
    company WHERE company.company_id = 82061]
    E0610 Error in executeQuery()
    E0606 executeQuery() error --
    E0701 Error in getResult().
    E0708 Command results in error - 1054 Unknown column
    'company.COMPANYPRODUCTSX' in 'field list'
    NestedThrowables:
    com.solarmetric.kodo.impl.jdbc.sql.SQLExceptionWrapper: [SQL=SELECT
    company.COMPANYPRODUCTSX FROM company WHERE company.company_id = 82061]
    E0610 Error in executeQuery()
    E0606 executeQuery() error --
    E0701 Error in getResult().
    E0708 Command results in error - 1054 Unknown column
    'company.COMPANYPRODUCTSX' in 'field list'
    I know i have probably set up the package.jdo file incorrectly, but I'm at a
    loss for what I did wrong.
    Any suggestions?
    Thanks!
    -Mike

    Hi,
    915766 wrote:
    I need to write sql for below requirement:
    table structure is
    serial no LPN
    1 4
    2 4
    3 6
    4 6
    5 6
    6 3
    7 3
    8 3
    9 1
    I have to pick distinct 'LPN' like below:That sounds like a job for "GROUP BY lpn".
    (any serial no can be picked for the distinct LPN)It looks like you're displaying the lowest serial_no for each lpn. That's easy to do, using the aggregate MIN function.
    results needs to be as below:
    serial no LPN
    1 4
    3 6
    6 3
    9 1
    Please suggest with sql.Here's one way:
    SELECT    MIN (serial_no)   AS serial_no
    ,         lpn
    FROM      table_x
    GROUP BY  lpn
    ORDER BY  lpn     -- if wanted
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • 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 relationship in hibernate

    I am very much new to hibernate,
    for testing purpose I am using JPA annotations and hibernate.
    While testing one to many relationship , I got a problem
    I have a PurchaseOrder class and OrderLine class having one to many relationship.
    package orderpackage;
    import java.util.ArrayList;
    import java.util.List;
    import javax.persistence.CascadeType;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
    @Entity
    public class PurchaseOrder {
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
      @OneToMany(cascade=CascadeType.ALL,mappedBy="order")
      private List <OrderLine> orderLine = new ArrayList<OrderLine>();
      public PurchaseOrder(String orderName) {
      this.orderName = orderName;
      public List<OrderLine> getOrderLine() {
      return orderLine;
      public void setOrderLine(List<OrderLine> orderLine) {
      this.orderLine = orderLine;
      private String orderName;
      public int getId() {
      return id;
      public void setId(int id) {
      this.id = id;
      public String getOrderName() {
      return orderName;
      public void setOrderName(String orderName) {
      this.orderName = orderName;
    OrderLine.java
    package orderpackage;
    import javax.persistence.CascadeType;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.ManyToOne;
    @Entity
    public class OrderLine {
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
      private String itemName;
      private int qty;
      @ManyToOne(cascade=CascadeType.ALL)
      private PurchaseOrder order;
      public OrderLine(String itemName, int qty) {
      this.itemName = itemName;
      this.qty = qty;
      public PurchaseOrder getOrder() {
      return order;
      public void setOrder(PurchaseOrder order) {
      this.order = order;
      public int getId() {
      return id;
      public void setId(int id) {
      this.id = id;
      public String getItemName() {
      return itemName;
      public void setItemName(String itemName) {
      this.itemName = itemName;
      public int getQty() {
      return qty;
      public void setQty(int qty) {
      this.qty = qty;
         OrderTest.java
    package orderpackage;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
    public class OrderTest {
      public static void main(String[] args) {
      PurchaseOrder order = new PurchaseOrder("order no 1");
      OrderLine orderLine1 = new OrderLine("item1",25);
      OrderLine orderLine2 = new OrderLine("item2",28);
      OrderLine orderLine3 = new OrderLine("item3",38);
      OrderLine orderLine4 = new OrderLine("item4",48);
      order.getOrderLine().add(orderLine1);
      order.getOrderLine().add(orderLine2);
      order.getOrderLine().add(orderLine3);
      order.getOrderLine().add(orderLine4);
      SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
      Session session = sessionFactory.openSession();
      session.beginTransaction();
      session.persist(order);
      session.getTransaction().commit();
      session.close();
    I can see Order and Order Line are get persisted but Order Line table don't have order_id populated automatically. Please help me out.

    That is because you're not setting it, obviously. Nowhere in your code are you actually populating the order property of the orderlines.

  • Need help mapping one-to-many relationship

    [Sorry, inadvertently cross-posted]
    Hello,
    I have a one-to-many mapping question that's probably a no-brainer for the
    experts of the group out there. My problem is that I can't get a collection
    of Items for a given Theme to be populated and I don't know if it's a
    problem in my system.jdo or in my classes (or both). For example, for Theme
    10,
    I want a collection of two Items, item_ids 1 and 2.
    I have db tables named ITEM and THEME with the following layouts:
    ITEM
    |==========================================================|
    | item_id(pk) | item_name | item_number | theme_id(fk) |
    |==========================================================|
    | 1 | This is Item1 | 1234 | 10 |
    | 2 | This is Item2 | 2954 | 10 |
    | 3 | This is Item3 | 2094 | 17 |
    | 4 | This is Item4 | 946 | 11 |
    | ... |
    |==========================================================|
    THEME
    |=======================================|
    | theme_id(pk) | theme_description |
    |=======================================|
    | 4 | Space |
    | 10 | Town |
    | 11 | Train |
    | 17 | Pirate |
    | ... |
    |=======================================|
    I have two PersistenceCapable classes that map to the above tables:
    package com.lego.data;
    public class Item
    public int item_id;
    private String item_number;
    private String item_name;
    private int theme_id;
    public Theme theme;
    public String toString()
    return
    item_number+":"+item_name+":"+theme.getCode()+":"+theme.getDescription();
    package com.lego.data;
    import java.util.*;
    public class Theme
    public int theme_id;
    public String theme_description;
    public Collection items;
    public String toString()
    return theme_id+":"+theme_description;
    and here is my system.jdo file:
    <?xml version = "1.0" encoding = "US-ASCII"?>
    <jdo>
    <package name="com.lego.data">
    <class name="Item" identity-type="application"
    objectid-class="com.lego.data.IntOId">
    <extension vendor-name="kodo" key="table" value="item"/>
    <extension vendor-name="kodo" key="lock-column" value="none"/>
    <extension vendor-name="kodo" key="class-column" value="none"/>
    <field name="item_id" primary-key="true">
    <extension vendor-name="kodo" key="data-column" value="item_id"/>
    </field>
    <field name="item_number">
    <extension vendor-name="kodo" key="data-column" value="item_number"/>
    </field>
    <field name="item_name">
    <extension vendor-name="kodo" key="data-column" value="item_name"/>
    </field>
    <field name="theme_id">
    <extension vendor-name="kodo" key="data-column" value="theme_id"/>
    </field>
    <field name="theme">
    <extension vendor-name="kodo" key="theme_id-data-column"
    value="theme_id"/>
    </field>
    </class>
    <class name="Theme" identity-type="application"
    objectid-class="com.lego.data.ThemeKey">
    <extension vendor-name="kodo" key="table" value="theme"/>
    <extension vendor-name="kodo" key="lock-column" value="none"/>
    <extension vendor-name="kodo" key="class-column" value="none"/>
    <field name="theme_id" primary-key="true">
    <extension vendor-name="kodo" key="data-column" value="theme_id"/>
    </field>
    <field name="theme_description">
    <extension vendor-name="kodo" key="data-column"
    value="theme_description"/>
    </field>
    <field name="items">
    <collection element-type="Item"/>
    <extension vendor-name="kodo" key="inverse" value="theme"/>
    </field>
    </class>
    </package>
    </jdo>
    Thanks in advance for the help.
    -Tim

    Abe White wrote:
    The first thing to check is that you are always setting the "theme" field in
    your Items. If you add an Item i to the "themes" collection of a Theme t, but
    forget to also set i's "theme" field to t, then the change will never get
    written to the database.
    Next, make sure that whenever you set the "theme" field of an Item, you also
    set
    its "theme_id" field. You map both of these fields to the same column, so you
    better be sure they stay in synch.
    On a related note, you might try making the "theme_id" field non-persistent if
    things still aren't working for you. Mapping two fields to the same column
    might be causing trouble. It would be safer to make theme_id non-persistent
    anyway, and to always grab the id from the Theme stored in your "theme"
    field.
    Better OO programming and all that, though I can see that you might have
    performance issues in mind when doing it your way.
    Anyway, if you find that it works when you make theme_id nonpersistent, let us
    know and we'll see why the double-mapping of the column is causing problems,
    and hopefully find a fix.Abe,
    Thanks for the response but I'm still confused. I failed to mention that
    the Item and Theme tables are in an existing schema, so as you saw in my
    system.jdo, I am specifying application identity.
    Since this is an existing schema, the Item table has theme_id as the
    foreign key to the Theme table. So are saying that it is a problem to map
    the both theme_id as a data column and a Theme object in the Item at the
    same time?
    I guess what I don't understand is exactly what my system.jdo should look
    like to map a one-to-many relationship. In my case, from Theme (1) to Item
    (many). (See my system.jdo in previous post).
    Thanks
    -Tim

  • 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!

  • ADF One to Many relationship

    I'm a bit confused on how to create one to many relationships with ADF. Let's say I have a make and model table. One make can have many models. Now let's say I create a Business Facade like this (I'm using JavaBeans):
    public Collection getMakes () { ... }
    Ok, my data control now has the collection for makes. And I want to do something like this
    public Collection getModels (Make make) { ... }
    I can't make this work because ADF will detect it as a method accesor. How does this work?
    Regards,
    Néstor Boscán

    Maybe looking at how TopLink does it, can help you.
    Try creating TopLink objects for a master detail set of tables (dept-emp).
    This will create two beans that should be similar to your beans. Look at their structure to see how they work.
    The ADF TopLink workshop has the steps to show you how to do this.
    http://www.oracle.com/technology/obe/obe9051jdev/ide1012/adfworkshop/buildingadfapplicationsworkshop.htm

  • JPA one to many relationship and serialization

    Hi,
    I modeled a one to may relationship like this:
    Parent Class WFData:
    @OneToMany(mappedBy = "wfData", targetEntity = Positionen.class)
    private Set<Positionen> positionen;
    Child Class Positionen
    @ManyToOne
    @JoinColumn(name = "WF_REF_ID", referencedColumnName = "ID")
    private WFData wfData;
    Now I want to create an EJB session bean with a method which returns an object of type WFData (parent) published as web service . When I try to deploy the web service I get the following error message: Unable to generate serialization framework for web service
    Does anyone know how to serialize a one-to-many relationship so I can use these objects in a web service?
    Best regards,
    Kevin

    I found the solution to get serialization correctly working and enable the service to be used in Visual Composer.
    You need to add the tag @XmlTransient to the getter method of the attribute in the child class that references the parent.
    @XmlTransient
    public WFData getWfData() {
        return wfData;

  • 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.

  • How to insert data in a one-to-many relationship

    How do you insert data into the client, my model entity beans have a one-to-many relationship.
    PARENT ENTITY BEAN
    PARENT-ID
    PARENT-NAME
    The ejbCreate(Integer parentID,String name)
    CHILD ENTITY BEAN
    CHILD-ID
    CHILD-NAME
    PARENT-ID(foreign key of PARENTID).
    ejbCreate(Integer parentID,String name,String foreignparentID)
    In a jsp page i collect the parent details and 3 corresponding chld details in a text box.
    Can you please tell me how do i proceed from here...
    ie. how to i insert data into the entity beans..
    Do i pass the child as a collection, and within parents ejbCreate() method do i lookup for the childs home interface and insert one -by -one from the collection.
    1. Considering the above example, can some one pls tell how the ejbCreate() mehod signatures, for the parent and child entity beans should be.
    2. Pls also show some sample client code as to how to make an insertion.
    3. In case you are passing a collection of child data, then in what format does one have to insert into a collection and also how does the container know how to insert the values in the child table , bcoz we are passing as a collection.
    4.In case collections cannot be inserted do we need to iterate into the collection in parent's ejbCreate() method, and manually insert into the database of the childtable, thereby creating child entity beans.
    Thanks for your time and support...
    regards
    kartik

    Hi,
    3. In this case of course child's ejbCreate(and postCreate) looks like
    ejbCreate(Integer childID,String name,ParentLocal parent) {
    setId(Id);
    setName(name);
    ejbPostCreate(Integer childID,String name,ParentLocal parent) {
    setParent(parent);
    Here you don't need IDs, but it happens only using Locals, not Remotes, if I'm not wrong. Container does it itself.
    1. Of course, if you have parent.getChildren() and parent.setChildren() then you don't need any loops, but it should be done anyway in postCreate, because in ejbCreate there no parent exists yet.
    Once more 3: example - I'm using JBoss 3.2.5 as EJB container. It has tomcat inside and EJB and JSP+Struts use the same jvm. It means for me that I don't need to use remote interfaces, just locals. And in this case I can implement ejb-relations. So, a have the abstract method parent.getChildren() which returns Collection of ChildLocal - s and method parent.setChildren(Collection childrenLocals) which creates/modifies children by itself.
    I have not used remotes for a long time, but as I remember it was not possible to implement ejb-relations using remotes.
    regards,
    Gio

  • Struggling with a one to many relationship in a sub-report

    Post Author: Scott_tansley
    CA Forum: General
    I have a database schema as per below: tblENQUIRY                 tblDatasheets                  tblReportParasIRSID (PK)       1 --> &  IRSID (FK)                       UID (PK)Attribute1                     SHEETID (PK)     1 > &  SHEETID (FK)Attribute2                     Attribute1                         LIST_ORDER                         tblStandardParasAttribute3                     Attribute2                         PARA_CODE (FK)    & < 1   CODE     (PK)etc...                            Attribute3                                                                     TEXT                                   etc...
    The PROBLEM I am a Crystal Reports Newbie, and having to work through things bit by bitu2026  I've managed to achieve quite a lot, but I'm totally stuck with this and would appreciate some help. I need to create a report (essentially a letter and some datasheets) around a one-to-many relationship, which I have managed to compile using a main report (for the one &#91;tblENQUIRY&#93;) and sub report (for the many &#91;tblDatasheets&#93;).  Essentially I need a covering letter, then the u2018manyu2019 datasheets, and then a number of other pages (which are largely static text). I have created a main report which includes the covering letter, holds a subreport for the datasheets, and then contains the text for the additional pages.  This all works fine, and I get the correct number of datasheets for each main report. My problem stems from the use of this sub report.  This sub-report needs to hold some attribute values for each datasheet, which is fine.  However, on each datasheet page I need to have some paragraphs, which are held in another one to many relationship.  Each datasheet may have up to six paragraphs held as a code in tblReportParas, with a relationship to the text as held in tblStandardParas. My original thought would have been to embed another sub report, containing the values from tblStandardParas!TEXT, into the first sub report.  However, I have found that it is not possible to have a sub-report inside another sub-report.  I had seperated the first sub-report out from the main report, and then embedded another sub-report into it.  This worked fine until I tried to stitch the sub-report back into the main report (at which point the sub-sub-report dissapeared from view). I have therefore reworked my sub-report a little, and the attribution is now stored in a pageheader, with the tblStandardParas!TEXT in a detail section below it.  This almost works! The only problem is that there is no relationship between the pageheader and detail sections.  To clarify, I would expect to have one datasheet, with the attribution at the top, and then the six paras below.  Then, the same on the next page (assuming there is a second datasheet) for that report.  Instead, I get the correct attribution, but the detail section actually gives every paragraph in the database, no matter which datasheet/or report it related to!  I therefore need to limit the detail section to only show those paragraphs where the SHEETID in tblReportParas is the same as the tblDatasheets SHEETID. Any offers of advice would be appreciated.

    Post Author: Scott_tansley
    CA Forum: General
    I managed to resolve this myself in the end.  I moves the tblEnquiry data into report header/footer sections, this allowed me to add the tblDatasheets information into the details section, which gave me multiple pages - and then finally, the Paragraphs were added through the use of a sub report. 
    There's probably an even better way, but for now it works, it's quick - and so I'm going to go with it!
    Thanks for your interest.

Maybe you are looking for

  • What's the best way to share JE environments between servlets?

    Hi, I'm happily serving requests for the same webapp (so single servlet) which uses multiple JE environments. In my case I have an environment for each db, one of these environments is a login details only db. Things work great, three questions thoug

  • Import IS_HEADER and IS_ITEM in BADI-BBP_CHANGE_DEFAULT

    Hi Team, I have a common requirement, I need to add 6 days to the default delivery date in the Shopping Cart.I have a Implemented BADI Using BADI Defination BBP_CHANGE_DEFAULT.In method Change_Default_Deliv_Date I have to import IS_Header and IS_ITEM

  • AME CC 2014 Rendering with only One Core

    This seems to have just begun recently (within the past month) where AME CC 2014 is only using 1 core (out of 12) to render video. No, this is not the CPU Parking issue - I have made the regedit tweaks and also changed my Power option to Performance,

  • How can I make Adobe Reader Touch remember where I left off?

    When I have closed a PDF, how can I make Adobe Reader Touch remember where I left off?

  • Re-Install (A New Start)

    Well I have been having problems lately with my iMac and want to start a new, basically a last resort, instead of buying more software I might as well use the software that I have got. Basically I want to re install Leopard. I have come to find that