Skip to content

Commit 55c5838

Browse files
committed
HHH-19324 - Switch tests using hbm.xml to use mapping.xml
HHH-19428 - Support @ListIndexBase in mapping.xml
1 parent 2adaf76 commit 55c5838

File tree

11 files changed

+217
-209
lines changed

11 files changed

+217
-209
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/bidi/AuctionTest2.java renamed to hibernate-core/src/test/java/org/hibernate/orm/test/bidi/Auction2Test.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
1616
import org.hibernate.testing.orm.junit.SessionFactory;
1717
import org.hibernate.testing.orm.junit.SessionFactoryScope;
18+
import org.junit.jupiter.api.AfterEach;
1819
import org.junit.jupiter.api.Test;
1920

2021
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -24,15 +25,18 @@
2425
/**
2526
* @author Gavin King
2627
*/
28+
@SuppressWarnings("JUnitMalformedDeclaration")
2729
@RequiresDialectFeature(
2830
feature = DialectFeatureChecks.SupportsExistsInSelectCheck.class,
2931
comment = "dialect does not support exist predicates in the select clause"
3032
)
31-
@DomainModel(
32-
xmlMappings = "org/hibernate/orm/test/bidi/Auction2.hbm.xml"
33-
)
33+
@DomainModel(xmlMappings = "org/hibernate/orm/test/bidi/Auction2.xml")
3434
@SessionFactory
35-
public class AuctionTest2 {
35+
public class Auction2Test {
36+
@AfterEach
37+
void dropTestData(SessionFactoryScope factoryScope) {
38+
factoryScope.dropData();
39+
}
3640

3741
@Test
3842
public void testLazy(SessionFactoryScope scope) {
@@ -58,7 +62,7 @@ public void testLazy(SessionFactoryScope scope) {
5862
session -> {
5963
Bid b = session.getReference( Bid.class, bidId );
6064
assertFalse( Hibernate.isInitialized( b ) );
61-
Auction a = session.get( Auction.class, aid );
65+
Auction a = session.find( Auction.class, aid );
6266
assertFalse( Hibernate.isInitialized( a.getBids() ) );
6367
assertFalse( Hibernate.isInitialized( a.getSuccessfulBid() ) );
6468
assertSame( a.getBids().iterator().next(), b );
@@ -103,9 +107,9 @@ public void testLazy(SessionFactoryScope scope) {
103107
Auction a = session.getReference( Auction.class, aid );
104108
assertFalse( Hibernate.isInitialized( b ) );
105109
assertFalse( Hibernate.isInitialized( a ) );
106-
assertSame( session.get( Bid.class, bidId ), b );
110+
assertSame( session.find( Bid.class, bidId ), b );
107111
assertTrue( Hibernate.isInitialized( b ) );
108-
assertSame( session.get( Auction.class, aid ), a );
112+
assertSame( session.find( Auction.class, aid ), a );
109113
assertTrue( Hibernate.isInitialized( a ) );
110114
assertSame( b, a.getSuccessfulBid() );
111115
assertSame( a, a.getSuccessfulBid().getItem() );

hibernate-core/src/test/java/org/hibernate/orm/test/bidi/AuctionTest.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.hibernate.testing.orm.junit.DomainModel;
1515
import org.hibernate.testing.orm.junit.SessionFactory;
1616
import org.hibernate.testing.orm.junit.SessionFactoryScope;
17+
import org.junit.jupiter.api.AfterEach;
1718
import org.junit.jupiter.api.Test;
1819

1920
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -23,11 +24,14 @@
2324
/**
2425
* @author Gavin King
2526
*/
26-
@DomainModel(
27-
xmlMappings = "org/hibernate/orm/test/bidi/Auction.hbm.xml"
28-
)
27+
@SuppressWarnings("JUnitMalformedDeclaration")
28+
@DomainModel(xmlMappings = "org/hibernate/orm/test/bidi/Auction.xml")
2929
@SessionFactory
3030
public class AuctionTest {
31+
@AfterEach
32+
void dropTestData(SessionFactoryScope factoryScope) {
33+
factoryScope.dropData();
34+
}
3135

3236
@Test
3337
public void testLazy(SessionFactoryScope scope) {
@@ -42,6 +46,7 @@ public void testLazy(SessionFactoryScope scope) {
4246
bid.setItem( auction );
4347
auction.getBids().add( bid );
4448
auction.setSuccessfulBid( bid );
49+
bid.setSuccessful( true );
4550

4651
scope.inTransaction(
4752
session ->
@@ -53,7 +58,7 @@ public void testLazy(SessionFactoryScope scope) {
5358

5459
scope.inTransaction(
5560
session -> {
56-
Bid b = session.get( Bid.class, bidId );
61+
Bid b = session.find( Bid.class, bidId );
5762
assertTrue( b.isSuccessful() );
5863
}
5964
);
@@ -63,7 +68,7 @@ public void testLazy(SessionFactoryScope scope) {
6368
Bid b = session.getReference( Bid.class, bidId );
6469
assertFalse( Hibernate.isInitialized( b ) );
6570

66-
Bid initializedBid = session.get( Bid.class, bidId );
71+
Bid initializedBid = session.find( Bid.class, bidId );
6772
assertSame( initializedBid, b );
6873
assertTrue( Hibernate.isInitialized( b ) );
6974
}
@@ -73,7 +78,7 @@ public void testLazy(SessionFactoryScope scope) {
7378
session -> {
7479
Bid b = session.getReference( Bid.class, bidId );
7580
assertFalse( Hibernate.isInitialized( b ) );
76-
Auction a = session.get( Auction.class, aid );
81+
Auction a = session.find( Auction.class, aid );
7782

7883
List<Bid> bids = a.getBids();
7984
assertFalse( Hibernate.isInitialized( bids ) );
@@ -125,9 +130,9 @@ public void testLazy(SessionFactoryScope scope) {
125130
Auction a = session.getReference( Auction.class, aid );
126131
assertFalse( Hibernate.isInitialized( b ) );
127132
assertFalse( Hibernate.isInitialized( a ) );
128-
assertSame( session.get( Bid.class, bidId ), b );
133+
assertSame( session.find( Bid.class, bidId ), b );
129134
assertTrue( Hibernate.isInitialized( b ) );
130-
assertSame( session.get( Auction.class, aid ), a );
135+
assertSame( session.find( Auction.class, aid ), a );
131136
assertTrue( Hibernate.isInitialized( a ) );
132137
assertSame( b, a.getSuccessfulBid() );
133138
assertFalse( Hibernate.isInitialized( a.getBids() ) );

hibernate-core/src/test/java/org/hibernate/orm/test/bidi/AuctionWithAbstractBidClassTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
import org.hibernate.testing.orm.junit.JiraKey;
1212
import org.hibernate.testing.orm.junit.DomainModel;
13-
import org.hibernate.testing.orm.junit.JiraKeyGroup;
1413
import org.hibernate.testing.orm.junit.SessionFactory;
1514
import org.hibernate.testing.orm.junit.SessionFactoryScope;
15+
import org.junit.jupiter.api.AfterEach;
1616
import org.junit.jupiter.api.Test;
1717

1818
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -21,17 +21,16 @@
2121
/**
2222
* @author Jan Schatteman
2323
*/
24-
@DomainModel(
25-
xmlMappings = "org/hibernate/orm/test/bidi/Auction3.hbm.xml"
26-
)
24+
@SuppressWarnings("JUnitMalformedDeclaration")
25+
@DomainModel(xmlMappings = "org/hibernate/orm/test/bidi/Auction3.xml")
2726
@SessionFactory
28-
@JiraKeyGroup(
29-
value = {
30-
@JiraKey( value = "HHH-987" ),
31-
@JiraKey( value = "HHH-992" )
32-
}
33-
)
27+
@JiraKey( value = "HHH-987" )
28+
@JiraKey( value = "HHH-992" )
3429
public class AuctionWithAbstractBidClassTest {
30+
@AfterEach
31+
void dropTestData(SessionFactoryScope factoryScope) {
32+
factoryScope.dropData();
33+
}
3534

3635
@Test
3736
public void testAbstractSuperClassMapping(SessionFactoryScope scope) {
@@ -66,7 +65,7 @@ public void testAbstractSuperClassMapping(SessionFactoryScope scope) {
6665

6766
scope.inTransaction(
6867
session -> {
69-
SpecialAuction auc = session.get( SpecialAuction.class, auctionId );
68+
SpecialAuction auc = session.find( SpecialAuction.class, auctionId );
7069
SpecialBid successfulBid = (SpecialBid) auc.getSuccessfulBid();
7170
assertTrue( successfulBid.isSuccessful() );
7271
assertEquals( successfulBid.getId(), ssbidId );

hibernate-core/src/test/java/org/hibernate/orm/test/collection/list/PersistentListTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public void testInverseListIndex(SessionFactoryScope scope) {
8585
connection -> {
8686
SimpleSelect select = new SimpleSelect( sessionFactory )
8787
.setTableName( collectionPersister.getTableName() )
88-
.addColumn( "NAME" )
89-
.addColumn( "LIST_INDEX" )
90-
.addRestriction( "NAME", ComparisonRestriction.Operator.NE, "?" );
88+
.addColumn( "name" )
89+
.addColumn( "list_index" )
90+
.addRestriction( "name", ComparisonRestriction.Operator.NE, "?" );
9191
final String sql = select.toStatementString();
9292
PreparedStatement preparedStatement = session2.getJdbcCoordinator() .getStatementPreparer()
9393
.prepareStatement( sql );
@@ -98,9 +98,9 @@ public void testInverseListIndex(SessionFactoryScope scope) {
9898
Map<String, Integer> valueMap = new HashMap<String, Integer>();
9999
while ( resultSet.next() ) {
100100
final String name = resultSet.getString( 1 );
101-
assertFalse( "NAME column was null", resultSet.wasNull() );
101+
assertFalse( "`name` column was null", resultSet.wasNull() );
102102
final int position = resultSet.getInt( 2 );
103-
assertFalse( "LIST_INDEX column was null", resultSet.wasNull() );
103+
assertFalse( "`list_index` column was null", resultSet.wasNull() );
104104
valueMap.put( name, position );
105105
}
106106
assertEquals( 2, valueMap.size() );

hibernate-core/src/test/resources/org/hibernate/orm/test/any/xml/Person.xml

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,4 @@
4343
</element-collection>
4444
</attributes>
4545
</entity>
46-
</entity-mappings>
47-
48-
<!--<!DOCTYPE hibernate-mapping PUBLIC-->
49-
<!-- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"-->
50-
<!-- "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">-->
51-
52-
<!--<hibernate-mapping package="org.hibernate.orm.test.any.xml">-->
53-
54-
<!-- <class name="Person" table="T_ANY_PERSON">-->
55-
<!-- <id name="id" column="ID_">-->
56-
<!-- <generator class="increment" />-->
57-
<!-- </id>-->
58-
<!-- <property name="name" />-->
59-
<!-- <any name="data" id-type="long" cascade="none">-->
60-
<!-- <meta-value value="A" class="Address"/>-->
61-
<!-- <column name="DATATYPE_"/>-->
62-
<!-- <column name="DATAID_"/>-->
63-
<!-- </any>-->
64-
<!-- </class>-->
65-
66-
<!-- <class name="Address" table="T_ANY_ADDRESS">-->
67-
<!-- <id name="id" column="ID_">-->
68-
<!-- <generator class="increment" />-->
69-
<!-- </id>-->
70-
<!-- <set name="lines" table="LINE">-->
71-
<!-- <key column="ADDRESS" />-->
72-
<!-- <element type="string" />-->
73-
<!-- </set>-->
74-
<!-- </class>-->
75-
76-
<!--</hibernate-mapping>-->
46+
</entity-mappings>

hibernate-core/src/test/resources/org/hibernate/orm/test/bidi/Auction.hbm.xml

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ SPDX-License-Identifier: Apache-2.0
4+
~ Copyright Red Hat Inc. and Hibernate Authors
5+
-->
6+
<entity-mappings xmlns="http://www.hibernate.org/xsd/orm/mapping"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
version="7.0">
9+
<package>org.hibernate.orm.test.bidi</package>
10+
11+
<entity class="Auction">
12+
<table name="auctions"/>
13+
<attributes>
14+
<id name="id">
15+
<generated-value generator="increment"/>
16+
</id>
17+
<basic name="description"/>
18+
<basic name="end">
19+
<column name="end_date_time"/>
20+
</basic>
21+
<many-to-one name="successfulBid">
22+
<join-column name="win_bid_fk"/>
23+
</many-to-one>
24+
<one-to-many name="bids" mapped-by="item">
25+
<cascade>
26+
<cascade-persist/>
27+
</cascade>
28+
</one-to-many>
29+
</attributes>
30+
</entity>
31+
32+
<entity class="Bid">
33+
<table name="bids"/>
34+
<attributes>
35+
<id name="id">
36+
<generated-value generator="increment"/>
37+
</id>
38+
<basic name="amount">
39+
<column scale="19" precision="31" />
40+
</basic>
41+
<basic name="datetime">
42+
<column name="creation_date_time"/>
43+
</basic>
44+
<basic name="successful">
45+
<column name="success"/>
46+
</basic>
47+
<many-to-one name="item">
48+
<join-column name="auction_fk"/>
49+
<cascade>
50+
<cascade-persist/>
51+
</cascade>
52+
</many-to-one>
53+
</attributes>
54+
</entity>
55+
56+
</entity-mappings>

hibernate-core/src/test/resources/org/hibernate/orm/test/bidi/Auction2.hbm.xml

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)