View | Details | Raw Unified | Return to bug 303110 | Differences between
and this patch

Collapse All | Expand All

(-)resource/eclipselink-annotation-model/persistence.xml (+1 lines)
Lines 66-71 Link Here
66
            <property name="eclipselink.orm.validate.schema" value="true"/>
66
            <property name="eclipselink.orm.validate.schema" value="true"/>
67
            <property name="javax.persistence.lock.timeout" value="5"/>
67
            <property name="javax.persistence.lock.timeout" value="5"/>
68
            <property name="eclipselink.id-validation" value="NEGATIVE"/>
68
            <property name="eclipselink.id-validation" value="NEGATIVE"/>
69
            <property name="javax.persistence.query.timeout" value="20"/>
69
        </properties>
70
        </properties>
70
    </persistence-unit>
71
    </persistence-unit>
71
    <persistence-unit name="default1">
72
    <persistence-unit name="default1">
(-)src/org/eclipse/persistence/testing/models/jpa/advanced/AdvancedTableCreator.java (-1 / +234 lines)
Lines 51-57 Link Here
51
        addTableDefinition(buildCONCURRENCYBTable());
51
        addTableDefinition(buildCONCURRENCYBTable());
52
        addTableDefinition(buildCONCURRENCYCTable());
52
        addTableDefinition(buildCONCURRENCYCTable());
53
        addTableDefinition(buildREADONLYISOLATED());
53
        addTableDefinition(buildREADONLYISOLATED());
54
        
54
        addTableDefinition(buildENTITYBTable());
55
        addTableDefinition(buildENTITYCTable());
56
        addTableDefinition(buildENTITYATable());
57
        addTableDefinition(buildENTITYDTable());
58
        addTableDefinition(buildADVENTITYAENTITYDTable());
59
        addTableDefinition(buildENTITYETable());
60
        addTableDefinition(buildADVENTITYAENTITYETable());
55
    }
61
    }
56
    
62
    
57
    public static TableDefinition buildADDRESSTable() {
63
    public static TableDefinition buildADDRESSTable() {
Lines 1488-1491 Link Here
1488
1494
1489
        return table;
1495
        return table;
1490
    }
1496
    }
1497
1498
    public static TableDefinition buildENTITYBTable() {
1499
         TableDefinition table = new TableDefinition();
1500
         table.setName("ADV_ENTYB");
1501
1502
         FieldDefinition fieldID = new FieldDefinition();
1503
         fieldID.setName("ID");
1504
         fieldID.setTypeName("NUMERIC");
1505
         fieldID.setSize(15);
1506
         fieldID.setSubSize(0);
1507
         fieldID.setIsPrimaryKey(true);
1508
         fieldID.setIsIdentity(true);
1509
         fieldID.setUnique(false);
1510
         fieldID.setShouldAllowNull(false);
1511
         table.addField(fieldID);
1512
1513
         FieldDefinition fieldNAME = new FieldDefinition();
1514
         fieldNAME.setName("NAME");
1515
         fieldNAME.setTypeName("VARCHAR2");
1516
         fieldNAME.setSize(60);
1517
         fieldNAME.setSubSize(0);
1518
         fieldNAME.setIsPrimaryKey(false);
1519
         fieldNAME.setIsIdentity(false);
1520
         fieldNAME.setUnique(false);
1521
         fieldNAME.setShouldAllowNull(true);
1522
         table.addField(fieldNAME);
1523
         
1524
         return table;
1525
     }
1526
1527
    public static TableDefinition buildENTITYATable() {
1528
         TableDefinition table = new TableDefinition();
1529
         table.setName("ADV_ENTYA");
1530
1531
         FieldDefinition fieldID = new FieldDefinition();
1532
         fieldID.setName("ID");
1533
         fieldID.setTypeName("NUMERIC");
1534
         fieldID.setSize(15);
1535
         fieldID.setSubSize(0);
1536
         fieldID.setIsPrimaryKey(true);
1537
         fieldID.setIsIdentity(true);
1538
         fieldID.setUnique(false);
1539
         fieldID.setShouldAllowNull(false);
1540
         table.addField(fieldID);
1541
1542
         FieldDefinition fieldNAME = new FieldDefinition();
1543
         fieldNAME.setName("NAME");
1544
         fieldNAME.setTypeName("VARCHAR2");
1545
         fieldNAME.setSize(60);
1546
         fieldNAME.setSubSize(0);
1547
         fieldNAME.setIsPrimaryKey(false);
1548
         fieldNAME.setIsIdentity(false);
1549
         fieldNAME.setUnique(false);
1550
         fieldNAME.setShouldAllowNull(true);
1551
         table.addField(fieldNAME);
1552
1553
         FieldDefinition fieldEntyB = new FieldDefinition();
1554
         fieldEntyB.setName("ENTYB_ID");
1555
         fieldEntyB.setTypeName("NUMERIC");
1556
         fieldEntyB.setSize(15);
1557
         fieldEntyB.setSubSize(0);
1558
         fieldEntyB.setIsPrimaryKey(false);
1559
         fieldEntyB.setIsIdentity(false);
1560
         fieldEntyB.setUnique(false);
1561
         fieldEntyB.setForeignKeyFieldName("ADV_ENTYB.ID");
1562
         table.addField(fieldEntyB);
1563
1564
         FieldDefinition fieldEntyC = new FieldDefinition();
1565
         fieldEntyC.setName("ENTYC_ID");
1566
         fieldEntyC.setTypeName("NUMERIC");
1567
         fieldEntyC.setSize(15);
1568
         fieldEntyC.setSubSize(0);
1569
         fieldEntyC.setIsPrimaryKey(false);
1570
         fieldEntyC.setIsIdentity(false);
1571
         fieldEntyC.setUnique(false);
1572
         fieldEntyC.setForeignKeyFieldName("ADV_ENTYC.ID");
1573
         table.addField(fieldEntyC);
1574
         
1575
         return table;
1576
     }
1577
1578
    public static TableDefinition buildENTITYDTable() {
1579
         TableDefinition table = new TableDefinition();
1580
         table.setName("ADV_ENTYD");
1581
1582
         FieldDefinition fieldID = new FieldDefinition();
1583
         fieldID.setName("ID");
1584
         fieldID.setTypeName("NUMERIC");
1585
         fieldID.setSize(15);
1586
         fieldID.setSubSize(0);
1587
         fieldID.setIsPrimaryKey(true);
1588
         fieldID.setIsIdentity(true);
1589
         fieldID.setUnique(false);
1590
         fieldID.setShouldAllowNull(false);
1591
         table.addField(fieldID);
1592
1593
         FieldDefinition fieldNAME = new FieldDefinition();
1594
         fieldNAME.setName("NAME");
1595
         fieldNAME.setTypeName("VARCHAR2");
1596
         fieldNAME.setSize(60);
1597
         fieldNAME.setSubSize(0);
1598
         fieldNAME.setIsPrimaryKey(false);
1599
         fieldNAME.setIsIdentity(false);
1600
         fieldNAME.setUnique(false);
1601
         fieldNAME.setShouldAllowNull(true);
1602
         table.addField(fieldNAME);
1603
         
1604
         return table;
1605
     }
1606
1607
    public static TableDefinition buildENTITYCTable() {
1608
         TableDefinition table = new TableDefinition();
1609
         table.setName("ADV_ENTYC");
1610
1611
         FieldDefinition fieldID = new FieldDefinition();
1612
         fieldID.setName("ID");
1613
         fieldID.setTypeName("NUMERIC");
1614
         fieldID.setSize(15);
1615
         fieldID.setSubSize(0);
1616
         fieldID.setIsPrimaryKey(true);
1617
         fieldID.setIsIdentity(true);
1618
         fieldID.setUnique(false);
1619
         fieldID.setShouldAllowNull(false);
1620
         table.addField(fieldID);
1621
1622
         FieldDefinition fieldNAME = new FieldDefinition();
1623
         fieldNAME.setName("NAME");
1624
         fieldNAME.setTypeName("VARCHAR2");
1625
         fieldNAME.setSize(60);
1626
         fieldNAME.setSubSize(0);
1627
         fieldNAME.setIsPrimaryKey(false);
1628
         fieldNAME.setIsIdentity(false);
1629
         fieldNAME.setUnique(false);
1630
         fieldNAME.setShouldAllowNull(true);
1631
         table.addField(fieldNAME);
1632
1633
         return table;
1634
     }
1635
1636
     public static TableDefinition buildADVENTITYAENTITYDTable() {
1637
        TableDefinition table = new TableDefinition();
1638
1639
        table.setName("ADV_ENTYA_ADV_ENTYD");
1640
1641
        FieldDefinition fieldORDERID = new FieldDefinition();
1642
        fieldORDERID.setName("EntyA_ID");
1643
        fieldORDERID.setTypeName("NUMERIC");
1644
        fieldORDERID.setSize(15);
1645
        fieldORDERID.setShouldAllowNull(false);
1646
        fieldORDERID.setIsPrimaryKey(false);
1647
        fieldORDERID.setUnique(false);
1648
        fieldORDERID.setIsIdentity(false);
1649
        fieldORDERID.setForeignKeyFieldName("ADV_ENTYA.ID");
1650
        table.addField(fieldORDERID);
1651
        
1652
        FieldDefinition fieldAUDITORID = new FieldDefinition();
1653
        fieldAUDITORID.setName("entyDs_ID");
1654
        fieldAUDITORID.setTypeName("NUMERIC");
1655
        fieldAUDITORID.setSize(15);
1656
        fieldAUDITORID.setShouldAllowNull(false);
1657
        fieldAUDITORID.setIsPrimaryKey(false);
1658
        fieldAUDITORID.setUnique(true);
1659
        fieldAUDITORID.setIsIdentity(false);
1660
        fieldAUDITORID.setForeignKeyFieldName("ADV_ENTYD.ID");
1661
        table.addField(fieldAUDITORID);
1662
    
1663
        return table;
1664
    }
1665
1666
     public static TableDefinition buildENTITYETable() {
1667
         TableDefinition table = new TableDefinition();
1668
         table.setName("ADV_ENTYE");
1669
1670
         FieldDefinition fieldID = new FieldDefinition();
1671
         fieldID.setName("ID");
1672
         fieldID.setTypeName("NUMERIC");
1673
         fieldID.setSize(15);
1674
         fieldID.setSubSize(0);
1675
         fieldID.setIsPrimaryKey(true);
1676
         fieldID.setIsIdentity(true);
1677
         fieldID.setUnique(false);
1678
         fieldID.setShouldAllowNull(false);
1679
         table.addField(fieldID);
1680
1681
         FieldDefinition fieldNAME = new FieldDefinition();
1682
         fieldNAME.setName("NAME");
1683
         fieldNAME.setTypeName("VARCHAR2");
1684
         fieldNAME.setSize(60);
1685
         fieldNAME.setSubSize(0);
1686
         fieldNAME.setIsPrimaryKey(false);
1687
         fieldNAME.setIsIdentity(false);
1688
         fieldNAME.setUnique(false);
1689
         fieldNAME.setShouldAllowNull(true);
1690
         table.addField(fieldNAME);
1691
         
1692
         return table;
1693
     }
1694
1695
     public static TableDefinition buildADVENTITYAENTITYETable() {
1696
        TableDefinition table = new TableDefinition();
1697
1698
        table.setName("ADV_ENTYA_ADV_ENTYE");
1699
1700
        FieldDefinition fieldORDERID = new FieldDefinition();
1701
        fieldORDERID.setName("EntyA_ID");
1702
        fieldORDERID.setTypeName("NUMERIC");
1703
        fieldORDERID.setSize(15);
1704
        fieldORDERID.setShouldAllowNull(false);
1705
        fieldORDERID.setIsPrimaryKey(false);
1706
        fieldORDERID.setUnique(false);
1707
        fieldORDERID.setIsIdentity(false);
1708
        fieldORDERID.setForeignKeyFieldName("ADV_ENTYA.ID");
1709
        table.addField(fieldORDERID);
1710
        
1711
        FieldDefinition fieldAUDITORID = new FieldDefinition();
1712
        fieldAUDITORID.setName("entyEs_ID");
1713
        fieldAUDITORID.setTypeName("NUMERIC");
1714
        fieldAUDITORID.setSize(15);
1715
        fieldAUDITORID.setShouldAllowNull(false);
1716
        fieldAUDITORID.setIsPrimaryKey(false);
1717
        fieldAUDITORID.setUnique(true);
1718
        fieldAUDITORID.setIsIdentity(false);
1719
        fieldAUDITORID.setForeignKeyFieldName("ADV_ENTYE.ID");
1720
        table.addField(fieldAUDITORID);
1721
    
1722
        return table;
1723
    }
1491
}
1724
}
(-)src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyA.java (+136 lines)
Line 0 Link Here
1
package org.eclipse.persistence.testing.models.jpa.advanced.entities;
2
3
import java.util.Collection;
4
5
import static javax.persistence.CascadeType.*;
6
import javax.persistence.Entity;
7
import javax.persistence.GeneratedValue;
8
import javax.persistence.Id;
9
import javax.persistence.OneToOne;
10
import javax.persistence.OneToMany;
11
import javax.persistence.ManyToMany;
12
import javax.persistence.JoinColumn;
13
import javax.persistence.Table;
14
15
@Entity
16
@Table(name = "ADV_ENTYA")
17
public class EntyA{
18
    
19
    @Id
20
    @GeneratedValue
21
    protected int id;
22
    
23
    protected String name;
24
    
25
    @OneToOne(cascade=PERSIST)
26
    protected EntyB entyB;
27
28
    @OneToOne(optional=false)
29
    @JoinColumn(name="ENTYC_ID", unique=true, nullable=false, updatable=false)
30
    protected EntyC entyC;
31
32
    @OneToMany(cascade={PERSIST})
33
    protected Collection<EntyD> entyDs;
34
35
    @ManyToMany(cascade={PERSIST, MERGE})
36
    protected Collection<EntyE> entyEs;
37
38
    /**
39
     * @return the id
40
     */
41
    public int getId() {
42
        return id;
43
    }
44
45
    /**
46
     * @param id the id to set
47
     */
48
    public void setId(int id) {
49
        this.id = id;
50
    }
51
52
    /**
53
     * @return the name
54
     */
55
    public String getName() {
56
        return name;
57
    }
58
59
    /**
60
     * @param name the name to set
61
     */
62
    public void setName(String name) {
63
        this.name = name;
64
    }
65
66
    /**
67
     * @return the entyB
68
     */
69
    public EntyB getEntyB() {
70
        return entyB;
71
    }
72
73
    /**
74
     * @param entyB the entyB to set
75
     */
76
    public void setEntyB(EntyB entyB) {
77
        this.entyB = entyB;
78
    }
79
80
    /**
81
     * @return the entyC
82
     */
83
84
    public EntyC getEntyC() {
85
        return entyC;
86
    }
87
88
    /**
89
     * @param entyC the entyC to set
90
     */
91
92
    public void setEntyC(EntyC entyC) {
93
        this.entyC = entyC;
94
    }
95
96
    /**
97
     * @return the entyD
98
     */
99
    public Collection<EntyD> getEntyDs() {
100
        return entyDs;
101
    }
102
103
    public void addEntyD(EntyD entyD) {
104
        getEntyDs().add(entyD);
105
    }
106
107
    public void removeEntyD(EntyD entyD) {
108
        getEntyDs().remove(entyD);
109
    }
110
111
    /**
112
     * @param entyD the entyD to set
113
     */
114
    public void setEntyDs(Collection<EntyD> entyDs) {
115
        this.entyDs = entyDs;
116
    }
117
118
    /**
119
     * @return the entyE
120
     */
121
    public Collection<EntyE> getEntyEs() {
122
        return entyEs;
123
    }
124
125
    public void addEntyE(EntyE entyE) {
126
        getEntyEs().add(entyE);
127
    }
128
129
    /**
130
     * @param entyE the entyE to set
131
     */
132
    public void setEntyEs(Collection<EntyE> entyEs) {
133
        this.entyEs = entyEs;
134
    }
135
136
}
(-)src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyB.java (+46 lines)
Line 0 Link Here
1
package org.eclipse.persistence.testing.models.jpa.advanced.entities;
2
3
import javax.persistence.Entity;
4
import javax.persistence.GeneratedValue;
5
import javax.persistence.Id;
6
import javax.persistence.Table;
7
8
@Entity
9
@Table(name = "ADV_ENTYB")
10
public class EntyB {
11
    
12
    @Id
13
    @GeneratedValue
14
    protected int id;
15
    
16
    protected String name;
17
    
18
    /**
19
     * @return the id
20
     */
21
    public int getId() {
22
        return id;
23
    }
24
25
    /**
26
     * @param id the id to set
27
     */
28
    public void setId(int id) {
29
        this.id = id;
30
    }
31
32
    /**
33
     * @return the name
34
     */
35
    public String getName() {
36
        return name;
37
    }
38
39
    /**
40
     * @param name the name to set
41
     */
42
    public void setName(String name) {
43
        this.name = name;
44
    }
45
46
}
(-)src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyC.java (+65 lines)
Line 0 Link Here
1
package org.eclipse.persistence.testing.models.jpa.advanced.entities;
2
3
import static javax.persistence.CascadeType.*;
4
import javax.persistence.Entity;
5
import javax.persistence.GeneratedValue;
6
import javax.persistence.Id;
7
import javax.persistence.OneToOne;
8
import javax.persistence.Table;
9
10
@Entity
11
@Table(name = "ADV_ENTYC")
12
public class EntyC {
13
    
14
    @Id
15
    @GeneratedValue
16
    protected int id;
17
    
18
    protected String name;
19
    
20
    @OneToOne(optional=false, mappedBy="entyC")
21
    protected EntyA entyA;
22
    /**
23
     * @return the id
24
     */
25
    public int getId() {
26
        return id;
27
    }
28
29
    /**
30
     * @param id the id to set
31
     */
32
    public void setId(int id) {
33
        this.id = id;
34
    }
35
36
    /**
37
     * @return the name
38
     */
39
    public String getName() {
40
        return name;
41
    }
42
43
    /**
44
     * @param name the name to set
45
     */
46
    public void setName(String name) {
47
        this.name = name;
48
    }
49
50
    /**
51
     * @return the entyA
52
     */
53
54
    public EntyA getEntyA() {
55
        return entyA;
56
    }
57
58
    /**
59
     * @param entyA the entyA to set
60
     */
61
62
    public void setEntyA(EntyA entyA) {
63
        this.entyA = entyA;
64
    }
65
}
(-)src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyD.java (+47 lines)
Line 0 Link Here
1
package org.eclipse.persistence.testing.models.jpa.advanced.entities;
2
3
import static javax.persistence.CascadeType.*;
4
import javax.persistence.Entity;
5
import javax.persistence.GeneratedValue;
6
import javax.persistence.Id;
7
import javax.persistence.Table;
8
9
@Entity
10
@Table(name = "ADV_ENTYD")
11
public class EntyD {
12
    
13
    @Id
14
    @GeneratedValue
15
    protected int id;
16
    
17
    protected String name;
18
    
19
    /**
20
     * @return the id
21
     */
22
    public int getId() {
23
        return id;
24
    }
25
26
    /**
27
     * @param id the id to set
28
     */
29
    public void setId(int id) {
30
        this.id = id;
31
    }
32
33
    /**
34
     * @return the name
35
     */
36
    public String getName() {
37
        return name;
38
    }
39
40
    /**
41
     * @param name the name to set
42
     */
43
    public void setName(String name) {
44
        this.name = name;
45
    }
46
47
}
(-)src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyE.java (+47 lines)
Line 0 Link Here
1
package org.eclipse.persistence.testing.models.jpa.advanced.entities;
2
3
import static javax.persistence.CascadeType.*;
4
import javax.persistence.Entity;
5
import javax.persistence.GeneratedValue;
6
import javax.persistence.Id;
7
import javax.persistence.Table;
8
9
@Entity
10
@Table(name = "ADV_ENTYE")
11
public class EntyE {
12
    
13
    @Id
14
    @GeneratedValue
15
    protected int id;
16
    
17
    protected String name;
18
    
19
    /**
20
     * @return the id
21
     */
22
    public int getId() {
23
        return id;
24
    }
25
26
    /**
27
     * @param id the id to set
28
     */
29
    public void setId(int id) {
30
        this.id = id;
31
    }
32
33
    /**
34
     * @return the name
35
     */
36
    public String getName() {
37
        return name;
38
    }
39
40
    /**
41
     * @param name the name to set
42
     */
43
    public void setName(String name) {
44
        this.name = name;
45
    }
46
47
}
(-)src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyA.java (+136 lines)
Line 0 Link Here
1
package org.eclipse.persistence.testing.models.jpa.advanced.entities;
2
3
import java.util.Collection;
4
5
import static javax.persistence.CascadeType.*;
6
import javax.persistence.Entity;
7
import javax.persistence.GeneratedValue;
8
import javax.persistence.Id;
9
import javax.persistence.OneToOne;
10
import javax.persistence.OneToMany;
11
import javax.persistence.ManyToMany;
12
import javax.persistence.JoinColumn;
13
import javax.persistence.Table;
14
15
@Entity
16
@Table(name = "ADV_ENTYA")
17
public class EntyA{
18
    
19
    @Id
20
    @GeneratedValue
21
    protected int id;
22
    
23
    protected String name;
24
    
25
    @OneToOne(cascade=PERSIST)
26
    protected EntyB entyB;
27
28
    @OneToOne(optional=false)
29
    @JoinColumn(name="ENTYC_ID", unique=true, nullable=false, updatable=false)
30
    protected EntyC entyC;
31
32
    @OneToMany(cascade={PERSIST})
33
    protected Collection<EntyD> entyDs;
34
35
    @ManyToMany(cascade={PERSIST, MERGE})
36
    protected Collection<EntyE> entyEs;
37
38
    /**
39
     * @return the id
40
     */
41
    public int getId() {
42
        return id;
43
    }
44
45
    /**
46
     * @param id the id to set
47
     */
48
    public void setId(int id) {
49
        this.id = id;
50
    }
51
52
    /**
53
     * @return the name
54
     */
55
    public String getName() {
56
        return name;
57
    }
58
59
    /**
60
     * @param name the name to set
61
     */
62
    public void setName(String name) {
63
        this.name = name;
64
    }
65
66
    /**
67
     * @return the entyB
68
     */
69
    public EntyB getEntyB() {
70
        return entyB;
71
    }
72
73
    /**
74
     * @param entyB the entyB to set
75
     */
76
    public void setEntyB(EntyB entyB) {
77
        this.entyB = entyB;
78
    }
79
80
    /**
81
     * @return the entyC
82
     */
83
84
    public EntyC getEntyC() {
85
        return entyC;
86
    }
87
88
    /**
89
     * @param entyC the entyC to set
90
     */
91
92
    public void setEntyC(EntyC entyC) {
93
        this.entyC = entyC;
94
    }
95
96
    /**
97
     * @return the entyD
98
     */
99
    public Collection<EntyD> getEntyDs() {
100
        return entyDs;
101
    }
102
103
    public void addEntyD(EntyD entyD) {
104
        getEntyDs().add(entyD);
105
    }
106
107
    public void removeEntyD(EntyD entyD) {
108
        getEntyDs().remove(entyD);
109
    }
110
111
    /**
112
     * @param entyD the entyD to set
113
     */
114
    public void setEntyDs(Collection<EntyD> entyDs) {
115
        this.entyDs = entyDs;
116
    }
117
118
    /**
119
     * @return the entyE
120
     */
121
    public Collection<EntyE> getEntyEs() {
122
        return entyEs;
123
    }
124
125
    public void addEntyE(EntyE entyE) {
126
        getEntyEs().add(entyE);
127
    }
128
129
    /**
130
     * @param entyE the entyE to set
131
     */
132
    public void setEntyEs(Collection<EntyE> entyEs) {
133
        this.entyEs = entyEs;
134
    }
135
136
}
(-)src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyB.java (+46 lines)
Line 0 Link Here
1
package org.eclipse.persistence.testing.models.jpa.advanced.entities;
2
3
import javax.persistence.Entity;
4
import javax.persistence.GeneratedValue;
5
import javax.persistence.Id;
6
import javax.persistence.Table;
7
8
@Entity
9
@Table(name = "ADV_ENTYB")
10
public class EntyB {
11
    
12
    @Id
13
    @GeneratedValue
14
    protected int id;
15
    
16
    protected String name;
17
    
18
    /**
19
     * @return the id
20
     */
21
    public int getId() {
22
        return id;
23
    }
24
25
    /**
26
     * @param id the id to set
27
     */
28
    public void setId(int id) {
29
        this.id = id;
30
    }
31
32
    /**
33
     * @return the name
34
     */
35
    public String getName() {
36
        return name;
37
    }
38
39
    /**
40
     * @param name the name to set
41
     */
42
    public void setName(String name) {
43
        this.name = name;
44
    }
45
46
}
(-)src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyC.java (+65 lines)
Line 0 Link Here
1
package org.eclipse.persistence.testing.models.jpa.advanced.entities;
2
3
import static javax.persistence.CascadeType.*;
4
import javax.persistence.Entity;
5
import javax.persistence.GeneratedValue;
6
import javax.persistence.Id;
7
import javax.persistence.OneToOne;
8
import javax.persistence.Table;
9
10
@Entity
11
@Table(name = "ADV_ENTYC")
12
public class EntyC {
13
    
14
    @Id
15
    @GeneratedValue
16
    protected int id;
17
    
18
    protected String name;
19
    
20
    @OneToOne(optional=false, mappedBy="entyC")
21
    protected EntyA entyA;
22
    /**
23
     * @return the id
24
     */
25
    public int getId() {
26
        return id;
27
    }
28
29
    /**
30
     * @param id the id to set
31
     */
32
    public void setId(int id) {
33
        this.id = id;
34
    }
35
36
    /**
37
     * @return the name
38
     */
39
    public String getName() {
40
        return name;
41
    }
42
43
    /**
44
     * @param name the name to set
45
     */
46
    public void setName(String name) {
47
        this.name = name;
48
    }
49
50
    /**
51
     * @return the entyA
52
     */
53
54
    public EntyA getEntyA() {
55
        return entyA;
56
    }
57
58
    /**
59
     * @param entyA the entyA to set
60
     */
61
62
    public void setEntyA(EntyA entyA) {
63
        this.entyA = entyA;
64
    }
65
}
(-)src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyD.java (+47 lines)
Line 0 Link Here
1
package org.eclipse.persistence.testing.models.jpa.advanced.entities;
2
3
import static javax.persistence.CascadeType.*;
4
import javax.persistence.Entity;
5
import javax.persistence.GeneratedValue;
6
import javax.persistence.Id;
7
import javax.persistence.Table;
8
9
@Entity
10
@Table(name = "ADV_ENTYD")
11
public class EntyD {
12
    
13
    @Id
14
    @GeneratedValue
15
    protected int id;
16
    
17
    protected String name;
18
    
19
    /**
20
     * @return the id
21
     */
22
    public int getId() {
23
        return id;
24
    }
25
26
    /**
27
     * @param id the id to set
28
     */
29
    public void setId(int id) {
30
        this.id = id;
31
    }
32
33
    /**
34
     * @return the name
35
     */
36
    public String getName() {
37
        return name;
38
    }
39
40
    /**
41
     * @param name the name to set
42
     */
43
    public void setName(String name) {
44
        this.name = name;
45
    }
46
47
}
(-)src/org/eclipse/persistence/testing/models/jpa/advanced/entities/EntyE.java (+47 lines)
Line 0 Link Here
1
package org.eclipse.persistence.testing.models.jpa.advanced.entities;
2
3
import static javax.persistence.CascadeType.*;
4
import javax.persistence.Entity;
5
import javax.persistence.GeneratedValue;
6
import javax.persistence.Id;
7
import javax.persistence.Table;
8
9
@Entity
10
@Table(name = "ADV_ENTYE")
11
public class EntyE {
12
    
13
    @Id
14
    @GeneratedValue
15
    protected int id;
16
    
17
    protected String name;
18
    
19
    /**
20
     * @return the id
21
     */
22
    public int getId() {
23
        return id;
24
    }
25
26
    /**
27
     * @param id the id to set
28
     */
29
    public void setId(int id) {
30
        this.id = id;
31
    }
32
33
    /**
34
     * @return the name
35
     */
36
    public String getName() {
37
        return name;
38
    }
39
40
    /**
41
     * @param name the name to set
42
     */
43
    public void setName(String name) {
44
        this.name = name;
45
    }
46
47
}
(-)src/org/eclipse/persistence/testing/tests/jpa/advanced/PessimisticLockingExtendedScopeTestSuite.java (+629 lines)
Line 0 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 1998, 2010 Oracle. All rights reserved.
3
 * This program and the accompanying materials are made available under the 
4
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
5
 * which accompanies this distribution. 
6
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7
 * and the Eclipse Distribution License is available at 
8
 * http://www.eclipse.org/org/documents/edl-v10.php.
9
 *
10
 * Contributors:
11
 *     Oracle - initial API and implementation from Oracle TopLink
12
 ******************************************************************************/  
13
package org.eclipse.persistence.testing.tests.jpa.advanced;
14
15
import org.eclipse.persistence.testing.framework.junit.JUnitTestCase;
16
import org.eclipse.persistence.testing.models.jpa.advanced.*;
17
import org.eclipse.persistence.testing.models.jpa.advanced.entities.*;
18
19
import java.util.ArrayList;
20
import java.util.Collection;
21
import java.util.HashMap;
22
import java.util.Map;
23
import junit.framework.Test;
24
import junit.framework.TestSuite;
25
26
import javax.persistence.EntityManager;
27
import javax.persistence.LockModeType;
28
import javax.persistence.PessimisticLockScope;
29
import javax.persistence.PersistenceException;
30
import javax.persistence.Query;
31
32
import org.eclipse.persistence.descriptors.ClassDescriptor;
33
import org.eclipse.persistence.config.QueryHints;
34
import org.eclipse.persistence.sessions.server.ServerSession;
35
36
/**
37
 * <p>
38
 * <b>Purpose</b>: Test Pessimistic Locking Extended Scope functionality.
39
 * <p>
40
 * <b>Description</b>: Test the relationship will be locked or unlocked under different situations
41
 * <p>
42
 */
43
 public class PessimisticLockingExtendedScopeTestSuite extends JUnitTestCase {
44
45
    public PessimisticLockingExtendedScopeTestSuite() {
46
        super();
47
    }
48
49
    public PessimisticLockingExtendedScopeTestSuite(String name) {
50
        super(name);
51
    }
52
53
    public static Test suite() {
54
        TestSuite suite = new TestSuite("PessimisticLocking ExtendedScope TestSuite");
55
        suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testSetup"));
56
        suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES1"));
57
        suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES2"));
58
        suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES3"));
59
        suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES4"));
60
        suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES5"));
61
        suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES6"));
62
        suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES7"));
63
        suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES8"));
64
        suite.addTest(new PessimisticLockingExtendedScopeTestSuite("testPESSMISTIC_ES9"));
65
        return suite;
66
    }
67
    
68
    public void testSetup() {
69
        ServerSession session = JUnitTestCase.getServerSession();
70
        new AdvancedTableCreator().replaceTables(session);
71
        //make the entity EquipmentCode read-write for the following tests
72
        ClassDescriptor descriptor = session.getDescriptor(EquipmentCode.class);
73
        boolean shouldBeReadOnly = descriptor.shouldBeReadOnly();
74
        descriptor.setShouldBeReadOnly(false);
75
        clearCache();
76
    }
77
    
78
    //Entity relationships for which the locked entity contains the foreign key will be locked with bidirectional one-to-one mapping without mappedBy (Scenario 1.1)
79
    public void testPESSMISTIC_ES1() throws Exception{
80
        // Cannot create parallel entity managers in the server.
81
        if (! isOnServer() && isSelectForUpateSupported()) {
82
            EntityManager em = createEntityManager();
83
            EntyA a = null;
84
            EntyC c = null;
85
            try{
86
                beginTransaction(em);
87
                a = new EntyA();
88
                c = new EntyC();
89
                em.persist(c);
90
                a.setName("test");
91
                a.setEntyC(c);
92
                em.persist(a);
93
                commitTransaction(em);
94
            }catch (RuntimeException ex){
95
                throw ex;
96
            }finally{
97
                if (isTransactionActive(em)){
98
                    rollbackTransaction(em);
99
                }
100
                closeEntityManager(em);
101
            }
102
103
            Exception lockTimeOutException = null;
104
            LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE;
105
            Map<String, Object> properties = new HashMap();
106
            properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED);
107
            EntityManager em1= createEntityManager();
108
109
            try{
110
                beginTransaction(em1);
111
                a = em1.find(EntyA.class, a.getId());
112
                em1.lock(a, lockMode, properties);
113
                EntityManager em2 = createEntityManager();
114
                try{
115
                    beginTransaction(em2);
116
                    a = em2.find(EntyA.class, a.getId());
117
                    a.setEntyC(null);
118
                    commitTransaction(em2);
119
                }catch(javax.persistence.RollbackException ex){
120
                    ex.printStackTrace();
121
                    if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){
122
                        ex.printStackTrace();
123
                        fail("it's not the right exception");
124
                    }
125
                }finally{
126
                    if (isTransactionActive(em2)){
127
                        rollbackTransaction(em2);
128
                    }
129
                    closeEntityManager(em2);
130
                }
131
            }catch (Exception ex){
132
                throw ex;
133
            }finally{
134
                if (isTransactionActive(em1)){
135
                    rollbackTransaction(em1);
136
                }
137
                closeEntityManager(em1);
138
            }
139
        }
140
    }
141
    
142
    //Entity relationships for which the locked entity contains the foreign key will be locked with unidirectional one-to-one mapping(Scenario 1.2)
143
    public void testPESSMISTIC_ES2() throws Exception{
144
        // Cannot create parallel entity managers in the server.
145
        if (! isOnServer() && isSelectForUpateSupported()) {
146
            EntityManager em = createEntityManager();
147
            EntyA a = null;
148
            EntyB b = null;
149
            try{
150
                beginTransaction(em);
151
                a = new EntyA();
152
                b = new EntyB();
153
                a.setEntyB(b);
154
                em.persist(a);
155
                commitTransaction(em);
156
            }catch (RuntimeException ex){
157
                throw ex;
158
            }finally{
159
                if (isTransactionActive(em)){
160
                    rollbackTransaction(em);
161
                }
162
                closeEntityManager(em);
163
            }
164
165
            Exception lockTimeOutException = null;
166
            LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE;
167
            Map<String, Object> properties = new HashMap();
168
            properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED);
169
            EntityManager em1= createEntityManager();
170
171
            try{
172
                beginTransaction(em1);
173
                a = em1.find(EntyA.class, a.getId());
174
                em1.lock(a, lockMode, properties);
175
                EntityManager em2 = createEntityManager();
176
                try{
177
                    beginTransaction(em2);
178
                    a = em2.find(EntyA.class, a.getId());
179
                    a.setEntyB(null);
180
                    commitTransaction(em2);
181
                }catch(javax.persistence.RollbackException ex){
182
                    if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){
183
                        ex.printStackTrace();
184
                        fail("it's not the right exception");
185
                    }
186
                }finally{
187
                    if (isTransactionActive(em2)){
188
                        rollbackTransaction(em2);
189
                    }
190
                    closeEntityManager(em2);
191
                }
192
            }catch (Exception ex){
193
                throw ex;
194
            }finally{
195
                if (isTransactionActive(em1)){
196
                    rollbackTransaction(em1);
197
                }
198
                closeEntityManager(em1);
199
            }
200
        }
201
    }
202
203
    //Entity relationships for which the locked entity contains the foreign key will be locked with unidirectional many-to-one mapping(Scenario 1.3)
204
    public void testPESSMISTIC_ES3() throws Exception{
205
        // Cannot create parallel entity managers in the server.
206
        if (! isOnServer() && isSelectForUpateSupported()) {
207
            EntityManager em = createEntityManager();
208
            Equipment eq = null;
209
            EquipmentCode eqCode = null;
210
            try{
211
                beginTransaction(em);
212
                eq = new Equipment();
213
                eqCode = new EquipmentCode();
214
                eqCode.setCode("A");
215
                em.persist(eqCode);
216
                eq.setEquipmentCode(eqCode);
217
                em.persist(eq);
218
                commitTransaction(em);
219
            }catch (RuntimeException ex){
220
                throw ex;
221
            }finally{
222
                if (isTransactionActive(em)){
223
                    rollbackTransaction(em);
224
                }
225
                closeEntityManager(em);
226
            }
227
228
            Exception lockTimeOutException = null;
229
            LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE;
230
            Map<String, Object> properties = new HashMap();
231
            properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED);
232
            EntityManager em1= createEntityManager();
233
234
            try{
235
                beginTransaction(em1);
236
                eq = em1.find(Equipment.class, eq.getId());
237
                em1.lock(eq, lockMode, properties);
238
                EntityManager em2 = createEntityManager();
239
                try{
240
                    beginTransaction(em2);
241
                    eq = em2.find(Equipment.class, eq.getId());
242
                    eq.setEquipmentCode(null);
243
                    commitTransaction(em2);
244
                }catch(javax.persistence.RollbackException ex){
245
                    if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){
246
                        ex.printStackTrace();
247
                        fail("it's not the right exception");
248
                    }
249
                }finally{
250
                    if (isTransactionActive(em2)){
251
                        rollbackTransaction(em2);
252
                    }
253
                    closeEntityManager(em2);
254
                }
255
            }catch (Exception ex){
256
                throw ex;
257
            }finally{
258
                if (isTransactionActive(em1)){
259
                    rollbackTransaction(em1);
260
                }
261
                closeEntityManager(em1);
262
            }
263
        }
264
    }
265
266
    //Entity relationships for which the locked entity contains the foreign key will be locked with bidirectional many-to-one mapping(Scenario 1.4)
267
    public void testPESSMISTIC_ES4() throws Exception{
268
        // Cannot create parallel entity managers in the server.
269
        if (! isOnServer() && isSelectForUpateSupported()) {
270
            EntityManager em = createEntityManager();
271
            Employee emp = null;
272
            Address ads = null;
273
            try{
274
                beginTransaction(em);
275
                emp = new Employee();
276
                ads = new Address("SomeStreet", "somecity", "province", "country", "postalcode");
277
                emp.setAddress(ads);
278
                em.persist(emp);
279
                commitTransaction(em);
280
            }catch (RuntimeException ex){
281
                throw ex;
282
            }finally{
283
                if (isTransactionActive(em)){
284
                    rollbackTransaction(em);
285
                }
286
                closeEntityManager(em);
287
            }
288
289
            Exception lockTimeOutException = null;
290
            LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE;
291
            Map<String, Object> properties = new HashMap();
292
            properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED);
293
            EntityManager em1= createEntityManager();
294
295
            try{
296
                beginTransaction(em1);
297
                emp = em1.find(Employee.class, emp.getId());
298
                em1.lock(emp, lockMode, properties);
299
                EntityManager em2 = createEntityManager();
300
                try{
301
                    beginTransaction(em2);
302
                    emp = em2.find(Employee.class, emp.getId());
303
                    Address address = null;
304
                    emp.setAddress(address);
305
                    commitTransaction(em2);
306
                }catch(javax.persistence.RollbackException ex){
307
                    if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){
308
                        ex.printStackTrace();
309
                        fail("it's not the right exception");
310
                    }
311
                }finally{
312
                    if (isTransactionActive(em2)){
313
                        rollbackTransaction(em2);
314
                    }
315
                    closeEntityManager(em2);
316
                }
317
            }catch (Exception ex){
318
                throw ex;
319
            }finally{
320
                if (isTransactionActive(em1)){
321
                    rollbackTransaction(em1);
322
                }
323
                closeEntityManager(em1);
324
            }
325
        }
326
    }
327
328
    //Relationships owned by the entity that are contained in join tables will be locked with Unidirectional OneToMany mapping (Scenario 2.2)
329
    public void testPESSMISTIC_ES5() throws Exception{
330
        // Cannot create parallel entity managers in the server.
331
        if (! isOnServer() && isSelectForUpateSupported()) {
332
            EntityManager em = createEntityManager();
333
            EntyA entyA = null;
334
            EntyD entyD = null;
335
            try{
336
                beginTransaction(em);
337
                entyA = new EntyA();
338
                em.persist(entyA);
339
                entyA.getEntyDs().add(new EntyD());
340
                commitTransaction(em);
341
            }catch (RuntimeException ex){
342
                throw ex;
343
            }finally{
344
                if (isTransactionActive(em)){
345
                    rollbackTransaction(em);
346
                }
347
                closeEntityManager(em);
348
            }
349
350
            Exception lockTimeOutException = null;
351
            LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE;
352
            Map<String, Object> properties = new HashMap();
353
            properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED);
354
            EntityManager em1= createEntityManager();
355
            try{
356
                beginTransaction(em1);
357
                entyA = em1.find(EntyA.class, entyA.getId());
358
                em1.lock(entyA, lockMode, properties);
359
                EntityManager em2 = createEntityManager();
360
                try{
361
                    beginTransaction(em2);
362
                    entyA = em2.find(EntyA.class, entyA.getId());
363
                    entyA.setEntyDs(null);
364
                    commitTransaction(em2);
365
                }catch(javax.persistence.RollbackException ex){
366
                    if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){
367
                        ex.printStackTrace();
368
                        fail("it's not the right exception");
369
                    }
370
                }finally{
371
                    if (isTransactionActive(em2)){
372
                        rollbackTransaction(em2);
373
                    }
374
                    closeEntityManager(em2);
375
                }
376
            }catch (Exception ex){
377
                throw ex;
378
            }finally{
379
                if (isTransactionActive(em1)){
380
                    rollbackTransaction(em1);
381
                }
382
                closeEntityManager(em1);
383
            }
384
        }
385
    }
386
387
    //Relationships owned by the entity that are contained in join tables will be locked with Unidirectional ManyToMany mapping (Scenario 2.3)
388
    public void testPESSMISTIC_ES6() throws Exception{
389
        // Cannot create parallel entity managers in the server.
390
        if (! isOnServer() && isSelectForUpateSupported()) {
391
            EntityManager em = createEntityManager();
392
            EntyA entyA = null;
393
            EntyE entyE1, entyE2 = null;
394
            try{
395
                beginTransaction(em);
396
                Collection entyEs = new ArrayList();
397
                entyA = new EntyA();
398
                entyE1 = new EntyE();
399
                entyE2 = new EntyE();
400
                entyEs.add(entyE1);
401
                entyEs.add(entyE2);
402
                entyA.setEntyEs(entyEs);
403
                em.persist(entyA);
404
                commitTransaction(em);
405
            }catch (RuntimeException ex){
406
                throw ex;
407
            }finally{
408
                if (isTransactionActive(em)){
409
                    rollbackTransaction(em);
410
                }
411
                closeEntityManager(em);
412
            }
413
414
            Exception lockTimeOutException = null;
415
            LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE;
416
            Map<String, Object> properties = new HashMap();
417
            properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.EXTENDED);
418
            EntityManager em1= createEntityManager();
419
            try{
420
                beginTransaction(em1);
421
                entyA = em1.find(EntyA.class, entyA.getId());
422
                em1.lock(entyA, lockMode, properties);
423
                EntityManager em2 = createEntityManager();
424
                try{
425
                    beginTransaction(em2);
426
                    entyA = em2.find(EntyA.class, entyA.getId());
427
                    entyA.setEntyEs(null);
428
                    commitTransaction(em2);
429
                }catch(javax.persistence.RollbackException ex){
430
                    if (ex.getMessage().indexOf("org.eclipse.persistence.exceptions.DatabaseException") == -1){
431
                        ex.printStackTrace();
432
                        fail("it's not the right exception");
433
                    }
434
                }finally{
435
                    if (isTransactionActive(em2)){
436
                        rollbackTransaction(em2);
437
                    }
438
                    closeEntityManager(em2);
439
                }
440
            }catch (Exception ex){
441
                throw ex;
442
            }finally{
443
                if (isTransactionActive(em1)){
444
                    rollbackTransaction(em1);
445
                }
446
                closeEntityManager(em1);
447
            }
448
        }
449
    }
450
451
    //Bidirectional OneToOne Relationship with target entity has foreign key, entity does not contain the foreign key will not be locked (Scenario 3.1)
452
    public void testPESSMISTIC_ES7() throws Exception{
453
        // Cannot create parallel entity managers in the server.
454
        if (! isOnServer() && isSelectForUpateSupported()) {
455
            EntityManager em = createEntityManager();
456
            EntyA a = null;
457
            EntyC c = null;
458
            try{
459
                beginTransaction(em);
460
                a = new EntyA();
461
                c = new EntyC();
462
                em.persist(c);
463
                a.setEntyC(c);
464
                em.persist(a);
465
                commitTransaction(em);
466
            }catch (RuntimeException ex){
467
                throw ex;
468
            }finally{
469
                if (isTransactionActive(em)){
470
                    rollbackTransaction(em);
471
                }
472
                closeEntityManager(em);
473
            }
474
475
            Exception lockTimeOutException = null;
476
            LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE;
477
            Map<String, Object> properties = new HashMap();
478
            properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.NORMAL);
479
            EntityManager em1= createEntityManager();
480
481
            try{
482
                beginTransaction(em1);
483
                c = em1.find(EntyC.class, c.getId());
484
                em1.lock(c, lockMode, properties);
485
                EntityManager em2 = createEntityManager();
486
                try{
487
                    beginTransaction(em2);
488
                    c = em2.find(EntyC.class, c.getId());
489
                    c.setEntyA(null);
490
                    commitTransaction(em2);
491
                }catch(javax.persistence.RollbackException ex){
492
                    fail("it should not throw the exception!!!");
493
                }finally{
494
                    if (isTransactionActive(em2)){
495
                        rollbackTransaction(em2);
496
                    }
497
                    closeEntityManager(em2);
498
                }
499
            }catch (Exception ex){
500
                throw ex;
501
            }finally{
502
                if (isTransactionActive(em1)){
503
                    rollbackTransaction(em1);
504
                }
505
                closeEntityManager(em1);
506
            }
507
        }
508
    }
509
510
    //Unidirectional OneToMany Relationship, in which entity does not contain the foreign key will not be locked (Scenario 3.2)
511
    public void testPESSMISTIC_ES8() throws Exception{
512
        // Cannot create parallel entity managers in the server.
513
        if (! isOnServer() && isSelectForUpateSupported()) {
514
            EntityManager em = createEntityManager();
515
            Employee emp = null;
516
            try{
517
                beginTransaction(em);
518
                emp = new Employee();
519
                emp.getDealers().add(new Dealer("Honda", "Kanata"));
520
                em.persist(emp);
521
                commitTransaction(em);
522
            }catch (RuntimeException ex){
523
                throw ex;
524
            }finally{
525
                if (isTransactionActive(em)){
526
                    rollbackTransaction(em);
527
                }
528
                closeEntityManager(em);
529
            }
530
531
            Exception lockTimeOutException = null;
532
            LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE;
533
            Map<String, Object> properties = new HashMap();
534
            properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.NORMAL);
535
            EntityManager em1= createEntityManager();
536
537
            try{
538
                beginTransaction(em1);
539
                emp = em1.find(Employee.class, emp.getId());
540
                em1.lock(emp, lockMode, properties);
541
                EntityManager em2 = createEntityManager();
542
                try{
543
                    beginTransaction(em2);
544
                    emp = em1.find(Employee.class, emp.getId());
545
                    emp.setDealers(null);
546
                    commitTransaction(em2);
547
                }catch(javax.persistence.RollbackException ex){
548
                    fail("it should not throw the exception!!!");
549
                }finally{
550
                    if (isTransactionActive(em2)){
551
                        rollbackTransaction(em2);
552
                    }
553
                    closeEntityManager(em2);
554
                }
555
            }catch (Exception ex){
556
                fail("it should not throw the exception!!!");
557
                throw ex;
558
            }finally{
559
                if (isTransactionActive(em1)){
560
                    rollbackTransaction(em1);
561
                }
562
                closeEntityManager(em1);
563
            }
564
        }
565
    }
566
567
    //Bidirectional ManyToMany Relationship, in which entity does not contain the foreign key will not be locked by default (Scenario 3.3)
568
    public void testPESSMISTIC_ES9() throws Exception{
569
        // Cannot create parallel entity managers in the server.
570
        if (! isOnServer() && isSelectForUpateSupported()) {
571
            EntityManager em = createEntityManager();
572
            Employee emp = null;
573
            try{
574
                beginTransaction(em);
575
                emp = new Employee();
576
                SmallProject smallProject = new SmallProject();
577
                smallProject.setName("New High School Set Up");
578
                emp.addProject(smallProject);
579
                LargeProject largeProject = new LargeProject();
580
                largeProject.setName("Downtown Light Rail");
581
                largeProject.setBudget(5000);
582
                emp.addProject(largeProject);
583
                em.persist(emp);
584
                commitTransaction(em);
585
            }catch (RuntimeException ex){
586
                throw ex;
587
            }finally{
588
                if (isTransactionActive(em)){
589
                    rollbackTransaction(em);
590
                }
591
                closeEntityManager(em);
592
            }
593
594
            Exception lockTimeOutException = null;
595
            LockModeType lockMode = LockModeType.PESSIMISTIC_WRITE;
596
            Map<String, Object> properties = new HashMap();
597
            properties.put(QueryHints.PESSIMISTIC_LOCK_SCOPE, PessimisticLockScope.NORMAL);
598
            EntityManager em1= createEntityManager();
599
600
            try{
601
                beginTransaction(em1);
602
                emp = em1.find(Employee.class, emp.getId());
603
                em1.lock(emp, lockMode, properties);
604
                EntityManager em2 = createEntityManager();
605
                try{
606
                    beginTransaction(em2);
607
                    emp = em1.find(Employee.class, emp.getId());
608
                    emp.setProjects(null);
609
                    commitTransaction(em2);
610
                }catch(javax.persistence.RollbackException ex){
611
                    fail("it should not throw the exception!!!");
612
                }finally{
613
                    if (isTransactionActive(em2)){
614
                        rollbackTransaction(em2);
615
                    }
616
                    closeEntityManager(em2);
617
                }
618
            }catch (Exception ex){
619
                fail("it should not throw the exception!!!");
620
                throw ex;
621
            }finally{
622
                if (isTransactionActive(em1)){
623
                    rollbackTransaction(em1);
624
                }
625
                closeEntityManager(em1);
626
            }
627
        }
628
    }
629
}
(-)src/org/eclipse/persistence/testing/tests/jpa/FullRegressionTestSuite.java (+2 lines)
Lines 36-41 Link Here
36
import org.eclipse.persistence.testing.tests.jpa.advanced.concurrency.LifecycleJUnitTest;
36
import org.eclipse.persistence.testing.tests.jpa.advanced.concurrency.LifecycleJUnitTest;
37
import org.eclipse.persistence.testing.tests.jpa.advanced.fetchgroup.AdvancedFetchGroupJunitTest;
37
import org.eclipse.persistence.testing.tests.jpa.advanced.fetchgroup.AdvancedFetchGroupJunitTest;
38
import org.eclipse.persistence.testing.tests.jpa.advanced.ReportQueryAdvancedJUnitTest;
38
import org.eclipse.persistence.testing.tests.jpa.advanced.ReportQueryAdvancedJUnitTest;
39
import org.eclipse.persistence.testing.tests.jpa.advanced.PessimisticLockingExtendedScopeTestSuite;
39
40
40
import org.eclipse.persistence.testing.tests.jpa.inheritance.LifecycleCallbackJunitTest;
41
import org.eclipse.persistence.testing.tests.jpa.inheritance.LifecycleCallbackJunitTest;
41
import org.eclipse.persistence.testing.tests.jpa.inheritance.DeleteAllQueryInheritanceJunitTest;
42
import org.eclipse.persistence.testing.tests.jpa.inheritance.DeleteAllQueryInheritanceJunitTest;
Lines 105-110 Link Here
105
        suite.addTest(AdvancedJunitTest.suite());
106
        suite.addTest(AdvancedJunitTest.suite());
106
        suite.addTest(AdvancedCompositePKJunitTest.suite());
107
        suite.addTest(AdvancedCompositePKJunitTest.suite());
107
        suite.addTest(AdvancedFetchGroupJunitTest.suite());
108
        suite.addTest(AdvancedFetchGroupJunitTest.suite());
109
        suite.addTest(PessimisticLockingExtendedScopeTestSuite.suite());
108
        fullSuite.addTest(suite);
110
        fullSuite.addTest(suite);
109
111
110
        // FieldAccess advanced model
112
        // FieldAccess advanced model

Return to bug 303110