Skip to content

Commit 7bba69f

Browse files
committed
HHH-19324 - Switch tests using hbm.xml to use mapping.xml
HHH-19433 - Deprecate @PropertyRef
1 parent 0abf2ae commit 7bba69f

File tree

14 files changed

+158
-178
lines changed

14 files changed

+158
-178
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/deletetransient/DeleteTransientEntityTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,16 @@
2424
/**
2525
* @author Steve Ebersole
2626
*/
27-
@DomainModel(
28-
xmlMappings = {
29-
"org/hibernate/orm/test/deletetransient/Person.hbm.xml"
30-
}
31-
)
27+
@SuppressWarnings("JUnitMalformedDeclaration")
28+
@DomainModel(xmlMappings = "org/hibernate/orm/test/deletetransient/Person.xml")
3229
@SessionFactory
3330
@BytecodeEnhanced
3431
@CustomEnhancementContext({ NoDirtyCheckingContext.class, DirtyCheckEnhancementContext.class })
3532
public class DeleteTransientEntityTest {
3633

3734
@AfterEach
3835
void tearDown(SessionFactoryScope scope) {
39-
scope.inTransaction( session -> session.createQuery( "from java.lang.Object", Object.class ).list().forEach( session::remove ) );
36+
scope.dropData();
4037
}
4138

4239
@Test

hibernate-core/src/test/java/org/hibernate/orm/test/connections/ConnectionManagementTestCase.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@
3131
*/
3232

3333
public abstract class ConnectionManagementTestCase extends BaseNonConfigCoreFunctionalTestCase {
34-
35-
@Override
36-
protected String getBaseForMappings() {
37-
return "org/hibernate/orm/test/";
38-
}
39-
4034
@Override
41-
public final String[] getMappings() {
42-
return new String[] { "connections/Silly.hbm.xml" };
35+
protected Class<?>[] getAnnotatedClasses() {
36+
return new Class<?>[] { Silly.class, Other.class };
4337
}
4438

4539

hibernate-core/src/test/java/org/hibernate/orm/test/connections/HibernateCreateBlobFailedCase.java

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,37 @@
44
*/
55
package org.hibernate.orm.test.connections;
66

7+
import org.hibernate.Session;
8+
import org.hibernate.engine.spi.SessionFactoryImplementor;
9+
import org.hibernate.testing.orm.junit.DomainModel;
10+
import org.hibernate.testing.orm.junit.ServiceRegistry;
11+
import org.hibernate.testing.orm.junit.SessionFactory;
12+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
13+
import org.hibernate.testing.orm.junit.Setting;
14+
import org.junit.jupiter.api.Test;
15+
716
import java.sql.Blob;
817
import java.sql.Clob;
918
import java.sql.SQLException;
1019

11-
import org.junit.Test;
12-
13-
import org.hibernate.Session;
14-
import org.hibernate.cfg.Configuration;
15-
import org.hibernate.cfg.Environment;
16-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
17-
18-
import static org.junit.Assert.assertFalse;
20+
import static org.hibernate.cfg.AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
1922

2023
/**
2124
* Test originally developed to verify and fix HHH-5550
2225
*
2326
* @author Steve Ebersole
2427
*/
25-
public class HibernateCreateBlobFailedCase extends BaseCoreFunctionalTestCase {
26-
27-
@Override
28-
protected String getBaseForMappings() {
29-
return "org/hibernate/orm/test/";
30-
}
31-
32-
@Override
33-
public String[] getMappings() {
34-
return new String[] { "connections/Silly.hbm.xml" };
35-
}
36-
37-
@Override
38-
public void configure(Configuration cfg) {
39-
super.configure( cfg );
40-
cfg.setProperty( Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread" );
41-
}
28+
@SuppressWarnings("JUnitMalformedDeclaration")
29+
@ServiceRegistry(settings = @Setting( name=CURRENT_SESSION_CONTEXT_CLASS, value = "thread"))
30+
@DomainModel(annotatedClasses = { Silly.class, Other.class })
31+
@SessionFactory
32+
public class HibernateCreateBlobFailedCase {
4233

4334
@Test
44-
public void testLobCreation() throws SQLException {
45-
Session session = sessionFactory().getCurrentSession();
35+
public void testLobCreation(SessionFactoryScope factoryScope) throws SQLException {
36+
final SessionFactoryImplementor sessionFactory = factoryScope.getSessionFactory();
37+
Session session = sessionFactory.getCurrentSession();
4638
session.beginTransaction();
4739
Blob blob = session.getLobHelper().createBlob( new byte[] {} );
4840
blob.free();

hibernate-core/src/test/java/org/hibernate/orm/test/connections/Other.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
package org.hibernate.orm.test.connections;
66

77

8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.GeneratedValue;
10+
import jakarta.persistence.Id;
11+
812
/**
913
* @author Steve Ebersole
1014
*/
15+
@Entity
1116
public class Other {
17+
@Id
18+
@GeneratedValue(generator = "increment")
1219
private Long id;
1320
private String name;
1421

hibernate-core/src/test/java/org/hibernate/orm/test/connections/Silly.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.orm.test.connections;
6+
import jakarta.persistence.Entity;
7+
import jakarta.persistence.GeneratedValue;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.JoinColumn;
10+
import jakarta.persistence.ManyToOne;
11+
612
import java.io.Serializable;
713

814
/**
9-
* Implementation of Silly.
10-
*
1115
* @author Steve Ebersole
1216
*/
17+
@Entity
1318
public class Silly implements Serializable {
19+
@Id
20+
@GeneratedValue(generator = "increment")
1421
private Long id;
1522
private String name;
23+
@ManyToOne
24+
@JoinColumn
1625
private Other other;
1726

1827
public Silly() {

hibernate-core/src/test/java/org/hibernate/orm/test/deletetransient/Address.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class Address {
1515
private Long id;
1616
private String info;
17-
private Set suites = new HashSet();
17+
private Set<Suite> suites = new HashSet<>();
1818

1919
public Address() {
2020
}
@@ -39,11 +39,11 @@ public void setInfo(String info) {
3939
this.info = info;
4040
}
4141

42-
public Set getSuites() {
42+
public Set<Suite> getSuites() {
4343
return suites;
4444
}
4545

46-
public void setSuites(Set suites) {
46+
public void setSuites(Set<Suite> suites) {
4747
this.suites = suites;
4848
}
4949
}

hibernate-core/src/test/java/org/hibernate/orm/test/deletetransient/Person.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
public class Person {
1717
private Long id;
1818
private String name;
19-
private Set addresses = new HashSet();
20-
private Collection friends = new ArrayList();
19+
private Set<Address> addresses = new HashSet<>();
20+
private Collection<Person> friends = new ArrayList<>();
2121

2222
public Person() {
2323
}
@@ -42,19 +42,19 @@ public void setName(String name) {
4242
this.name = name;
4343
}
4444

45-
public Set getAddresses() {
45+
public Set<Address> getAddresses() {
4646
return addresses;
4747
}
4848

49-
public void setAddresses(Set addresses) {
49+
public void setAddresses(Set<Address> addresses) {
5050
this.addresses = addresses;
5151
}
5252

53-
public Collection getFriends() {
53+
public Collection<Person> getFriends() {
5454
return friends;
5555
}
5656

57-
public void setFriends(Collection friends) {
57+
public void setFriends(Collection<Person> friends) {
5858
this.friends = friends;
5959
}
6060
}

hibernate-core/src/test/java/org/hibernate/orm/test/deletetransient/Suite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public class Suite {
1414
private Long id;
1515
private String location;
16-
private Set notes = new HashSet();
16+
private Set<Note> notes = new HashSet<>();
1717

1818
public Suite() {
1919
}
@@ -38,11 +38,11 @@ public void setLocation(String location) {
3838
this.location = location;
3939
}
4040

41-
public Set getNotes() {
41+
public Set<Note> getNotes() {
4242
return notes;
4343
}
4444

45-
public void setNotes(Set notes) {
45+
public void setNotes(Set<Note> notes) {
4646
this.notes = notes;
4747
}
4848
}

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/function/Product.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,39 @@
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
55
package org.hibernate.orm.test.dialect.function;
6+
import jakarta.persistence.Entity;
7+
import jakarta.persistence.Id;
8+
69
import java.math.BigDecimal;
710
import java.util.Date;
811

912
/**
10-
*
1113
* @author Strong Liu
12-
*
1314
*/
15+
@Entity
1416
public class Product {
17+
@Id
1518
private Long id;
1619
private int length;
1720
private long weight;
1821
private BigDecimal price;
1922
private Date date;
2023

24+
public Product() {
25+
}
26+
27+
public Product(Long id) {
28+
this.id = id;
29+
}
30+
31+
public Product(Long id, int length, long weight, BigDecimal price, Date date) {
32+
this.id = id;
33+
this.length = length;
34+
this.weight = weight;
35+
this.price = price;
36+
this.date = date;
37+
}
38+
2139
public Long getId() {
2240
return id;
2341
}

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/function/SybaseASEFunctionTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,20 @@
2525
import org.junit.jupiter.api.Test;
2626

2727
/**
28-
*
2928
* @author Richard H. Tingstad
3029
*/
31-
@DomainModel(
32-
xmlMappings = "org/hibernate/orm/test/dialect/function/Product.hbm.xml"
33-
)
30+
@DomainModel(annotatedClasses = Product.class)
3431
@SessionFactory
3532
@RequiresDialect(value = SybaseASEDialect.class)
36-
@SuppressWarnings("rawtypes")
33+
@SuppressWarnings({"rawtypes", "JUnitMalformedDeclaration"})
3734
public class SybaseASEFunctionTest {
3835

3936
@BeforeAll
4037
protected void prepareTest(SessionFactoryScope scope) throws Exception {
4138
scope.inTransaction(
4239
session -> {
43-
Product product = new Product();
44-
product.setPrice(new BigDecimal("0.5"));
40+
Product product = new Product( 1L );
41+
product.setPrice( new BigDecimal("0.5") );
4542
product.setDate( Calendar.getInstance().getTime() );
4643
session.persist( product );
4744
}
@@ -50,9 +47,7 @@ protected void prepareTest(SessionFactoryScope scope) throws Exception {
5047

5148
@AfterAll
5249
protected void cleanupTest(SessionFactoryScope scope) throws Exception {
53-
scope.inTransaction(
54-
session -> session.createQuery( "delete from Product" ).executeUpdate()
55-
);
50+
scope.dropData();
5651
}
5752

5853
@Test

0 commit comments

Comments
 (0)