Skip to content

Commit c39b3f9

Browse files
committed
Various code cleanup
1 parent cf41e60 commit c39b3f9

File tree

4 files changed

+61
-143
lines changed

4 files changed

+61
-143
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/stateless/insert/Message.java

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

hibernate-core/src/test/java/org/hibernate/orm/test/stateless/insert/MessageRecipient.java

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

hibernate-core/src/test/java/org/hibernate/orm/test/stateless/insert/StatelessSessionInsertTest.java

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,83 @@
44
*/
55
package org.hibernate.orm.test.stateless.insert;
66

7-
import org.hibernate.cfg.MappingSettings;
8-
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.JoinColumn;
10+
import jakarta.persistence.ManyToOne;
11+
import jakarta.persistence.Table;
12+
import org.hibernate.StatelessSession;
913
import org.hibernate.testing.orm.junit.DomainModel;
10-
import org.hibernate.testing.orm.junit.ServiceRegistry;
1114
import org.hibernate.testing.orm.junit.SessionFactory;
1215
import org.hibernate.testing.orm.junit.SessionFactoryScope;
13-
import org.hibernate.testing.orm.junit.Setting;
1416
import org.junit.jupiter.api.AfterEach;
1517
import org.junit.jupiter.api.Test;
1618

1719
/**
18-
20+
* Simple "smoke" test of {@linkplain StatelessSession#insert} with associations
1921
*/
20-
@ServiceRegistry(settings = @Setting(name = MappingSettings.TRANSFORM_HBM_XML, value = "true"))
21-
@DomainModel(xmlMappings = "org/hibernate/orm/test/stateless/insert/Mappings.hbm.xml")
22+
@SuppressWarnings("JUnitMalformedDeclaration")
23+
@DomainModel(annotatedClasses = {
24+
StatelessSessionInsertTest.Department.class,
25+
StatelessSessionInsertTest.Employee.class,
26+
})
2227
@SessionFactory
2328
public class StatelessSessionInsertTest {
2429

2530
@Test
2631
public void testInsertWithForeignKey(SessionFactoryScope scope) {
27-
Message msg = new Message();
28-
scope.inTransaction(
29-
session -> {
30-
final String messageId = "message_id";
31-
msg.setId( messageId );
32-
msg.setContent( "message_content" );
33-
msg.setSubject( "message_subject" );
34-
session.persist( msg );
35-
}
36-
);
37-
38-
scope.inStatelessTransaction(
39-
statelessSession -> {
40-
MessageRecipient signature = new MessageRecipient();
41-
signature.setId( "recipient" );
42-
signature.setEmail( "[email protected]" );
43-
signature.setMessage( msg );
44-
statelessSession.insert( signature );
45-
}
46-
);
32+
final Department department = scope.fromTransaction( (session) -> {
33+
final Department dept = new Department( 1, "Marketing" );
34+
session.persist( dept );
35+
return dept;
36+
} );
37+
38+
scope.inStatelessTransaction( (statelessSession) -> {
39+
final Employee employee = new Employee( 1, "John Jacobs", department );
40+
statelessSession.insert( employee );
41+
} );
4742
}
4843

4944
@AfterEach
5045
public void cleanup(SessionFactoryScope scope) {
51-
scope.inTransaction(
52-
session -> {
53-
session.createQuery( "delete MessageRecipient" ).executeUpdate();
54-
session.createQuery( "delete Message" ).executeUpdate();
55-
}
56-
);
46+
scope.dropData();
47+
}
48+
49+
@Entity
50+
@Table(name = "departments")
51+
@SuppressWarnings({"FieldCanBeLocal", "unused"})
52+
public static class Department {
53+
@Id
54+
private Integer id;
55+
private String name;
56+
57+
public Department() {
58+
}
59+
60+
public Department(Integer id, String name) {
61+
this.id = id;
62+
this.name = name;
63+
}
64+
}
65+
66+
@Entity
67+
@Table(name = "employees")
68+
@SuppressWarnings({"FieldCanBeLocal", "unused"})
69+
public static class Employee {
70+
@Id
71+
private Integer id;
72+
private String name;
73+
@ManyToOne
74+
@JoinColumn(name = "msg_fk")
75+
private Department department;
76+
77+
public Employee() {
78+
}
79+
80+
public Employee(Integer id, String name, Department department) {
81+
this.id = id;
82+
this.name = name;
83+
this.department = department;
84+
}
5785
}
5886
}

hibernate-core/src/test/resources/org/hibernate/orm/test/stateless/insert/Mappings.hbm.xml

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

0 commit comments

Comments
 (0)