44 */
55package org .hibernate .orm .test .annotations .onetomany ;
66
7- import java .util .ArrayList ;
8- import java .util .Collection ;
9- import java .util .Collections ;
10- import java .util .HashSet ;
11- import java .util .Iterator ;
12- import java .util .List ;
13- import java .util .Map ;
14- import java .util .Set ;
15- import java .util .SortedSet ;
16- import java .util .TreeSet ;
17- import jakarta .persistence .CascadeType ;
18- import jakarta .persistence .Entity ;
19- import jakarta .persistence .GeneratedValue ;
20- import jakarta .persistence .Id ;
21- import jakarta .persistence .JoinColumn ;
22- import jakarta .persistence .OneToMany ;
237import jakarta .persistence .PersistenceException ;
24-
25- import org .hibernate .AnnotationException ;
268import org .hibernate .Hibernate ;
279import org .hibernate .Session ;
2810import org .hibernate .Transaction ;
29- import org .hibernate .annotations .OnDelete ;
30- import org .hibernate .annotations .OnDeleteAction ;
31- import org .hibernate .boot .MetadataSources ;
32- import org .hibernate .boot .registry .StandardServiceRegistry ;
33- import org .hibernate .boot .registry .StandardServiceRegistryBuilder ;
3411import org .hibernate .exception .ConstraintViolationException ;
3512import org .hibernate .mapping .Column ;
3613import org .hibernate .mapping .PersistentClass ;
3714import org .hibernate .mapping .Table ;
3815import org .hibernate .metamodel .CollectionClassification ;
39-
40- import org .hibernate .testing .DialectChecks ;
41- import org .hibernate .testing .RequiresDialectFeature ;
42- import org .hibernate .testing .orm .junit .JiraKey ;
43- import org .hibernate .testing .junit4 .BaseNonConfigCoreFunctionalTestCase ;
44- import org .hibernate .testing .util .ServiceRegistryUtil ;
45-
4616import org .hibernate .orm .test .annotations .Customer ;
4717import org .hibernate .orm .test .annotations .Discount ;
4818import org .hibernate .orm .test .annotations .Passport ;
4919import org .hibernate .orm .test .annotations .Ticket ;
5020import org .hibernate .orm .test .annotations .TicketComparator ;
21+ import org .hibernate .testing .junit4 .BaseNonConfigCoreFunctionalTestCase ;
22+ import org .hibernate .testing .orm .junit .JiraKey ;
5123import org .junit .Assert ;
5224import org .junit .Test ;
5325
26+ import java .util .ArrayList ;
27+ import java .util .Collection ;
28+ import java .util .HashSet ;
29+ import java .util .Iterator ;
30+ import java .util .List ;
31+ import java .util .Map ;
32+ import java .util .Set ;
33+ import java .util .SortedSet ;
34+ import java .util .TreeSet ;
35+
5436import static org .hibernate .cfg .AvailableSettings .DEFAULT_LIST_SEMANTICS ;
5537import static org .hibernate .testing .junit4 .ExtraAssertions .assertTyping ;
56- import static org .hibernate .testing .transaction .TransactionUtil .doInHibernate ;
5738import static org .junit .Assert .assertEquals ;
5839import static org .junit .Assert .assertFalse ;
5940import static org .junit .Assert .assertNotNull ;
@@ -363,46 +344,6 @@ public void testCascadeDelete() throws Exception {
363344 s .close ();
364345 }
365346
366- @ Test
367- @ RequiresDialectFeature (DialectChecks .SupportsCascadeDeleteCheck .class )
368- public void testCascadeDeleteWithUnidirectionalAssociation () throws Exception {
369- OnDeleteUnidirectionalOneToManyChild child = new OnDeleteUnidirectionalOneToManyChild ();
370-
371- doInHibernate ( this ::sessionFactory , session -> {
372- OnDeleteUnidirectionalOneToManyParent parent = new OnDeleteUnidirectionalOneToManyParent ();
373- parent .children = Collections .singletonList ( child );
374- session .persist ( parent );
375- } );
376-
377- doInHibernate ( this ::sessionFactory , session -> {
378- session .createQuery ("delete from OnDeleteUnidirectionalOneToManyParent" ).executeUpdate ();
379- } );
380-
381- doInHibernate ( this ::sessionFactory , session -> {
382- OnDeleteUnidirectionalOneToManyChild e1 = session .get ( OnDeleteUnidirectionalOneToManyChild .class , child .id );
383- assertNull ( "delete cascade should work" , e1 );
384- } );
385- }
386-
387- @ Test
388- public void testOnDeleteWithoutJoinColumn () throws Exception {
389- StandardServiceRegistry serviceRegistry = ServiceRegistryUtil .serviceRegistry ();
390-
391- try {
392- new MetadataSources ( serviceRegistry )
393- .addAnnotatedClass ( OnDeleteUnidirectionalOneToMany .class )
394- .addAnnotatedClass ( ParentUnawareChild .class )
395- .getMetadataBuilder ()
396- .build ();
397- }
398- catch ( AnnotationException e ) {
399- assertTrue (e .getMessage ().contains ( "is annotated '@OnDelete' and must explicitly specify a '@JoinColumn'" ));
400- }
401- finally {
402- StandardServiceRegistryBuilder .destroy ( serviceRegistry );
403- }
404- }
405-
406347 @ Test
407348 public void testSimpleOneToManySet () throws Exception {
408349 Session s ;
@@ -561,9 +502,7 @@ protected Class[] getAnnotatedClasses() {
561502 Person .class ,
562503 Organisation .class ,
563504 OrganisationUser .class ,
564- Model .class ,
565- OnDeleteUnidirectionalOneToManyParent .class ,
566- OnDeleteUnidirectionalOneToManyChild .class
505+ Model .class
567506 };
568507 }
569508
@@ -579,46 +518,4 @@ protected void addSettings(Map<String,Object> settings) {
579518 settings .put ( DEFAULT_LIST_SEMANTICS , CollectionClassification .BAG .name () );
580519 }
581520
582- @ Entity (name = "OnDeleteUnidirectionalOneToManyParent" )
583- @ jakarta .persistence .Table (name = "OneToManyParent" )
584- public static class OnDeleteUnidirectionalOneToManyParent {
585-
586- @ Id
587- @ GeneratedValue
588- Long id ;
589-
590- @ OneToMany (cascade = CascadeType .ALL )
591- @ JoinColumn (name = "a_id" )
592- @ OnDelete (action = OnDeleteAction .CASCADE )
593- List <OnDeleteUnidirectionalOneToManyChild > children ;
594- }
595-
596- @ Entity (name = "OnDeleteUnidirectionalOneToManyChild" )
597- @ jakarta .persistence .Table (name = "OneToManyChild" )
598- public static class OnDeleteUnidirectionalOneToManyChild {
599-
600- @ Id
601- @ GeneratedValue
602- Long id ;
603- }
604-
605- @ Entity (name = "OnDeleteUnidirectionalOneToMany" )
606- @ jakarta .persistence .Table (name = "OneToMany" )
607- public static class OnDeleteUnidirectionalOneToMany {
608-
609- @ Id
610- Long id ;
611-
612- @ OneToMany (cascade = CascadeType .ALL )
613- @ OnDelete (action = OnDeleteAction .CASCADE )
614- List <ParentUnawareChild > children ;
615- }
616-
617- @ Entity (name = "ParentUnawareChild" )
618- @ jakarta .persistence .Table (name = "Child" )
619- public static class ParentUnawareChild {
620-
621- @ Id
622- Long id ;
623- }
624521}
0 commit comments