- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.7k
HHH-19076 Resolve member of MappedSuperclass specially #10475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            3 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
        
          
          
            199 changes: 199 additions & 0 deletions
          
          199 
        
  ...ava/org/hibernate/orm/test/mapping/identifier/composite/CompositeInheritanceFailTest.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.orm.test.mapping.identifier.composite; | ||
|  | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.IdClass; | ||
| import jakarta.persistence.MappedSuperclass; | ||
| import jakarta.persistence.Version; | ||
| import org.hibernate.cfg.AvailableSettings; | ||
| import org.hibernate.testing.orm.junit.DomainModel; | ||
| import org.hibernate.testing.orm.junit.Jira; | ||
| import org.hibernate.testing.orm.junit.ServiceRegistry; | ||
| import org.hibernate.testing.orm.junit.SessionFactory; | ||
| import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
| import org.hibernate.testing.orm.junit.Setting; | ||
| import org.junit.jupiter.api.Test; | ||
|  | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|  | ||
| /** | ||
| * This test Fails | ||
| */ | ||
| @DomainModel( | ||
| annotatedClasses = { | ||
| CompositeInheritanceFailTest.TupAbstractEntity.class, | ||
| CompositeInheritanceFailTest.DummyEntity.class, | ||
| CompositeInheritanceFailTest.TestEntity.class, // Here the class is called TestEntity | ||
| CompositeInheritanceFailTest.Test2Entity.class, | ||
| } | ||
| ) | ||
| @ServiceRegistry( | ||
| settings = { | ||
| // For your own convenience to see generated queries: | ||
| @Setting(name = AvailableSettings.SHOW_SQL, value = "true"), | ||
| @Setting(name = AvailableSettings.FORMAT_SQL, value = "true"), | ||
| // @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ), | ||
| } | ||
| ) | ||
| @SessionFactory | ||
| @Jira("HHH-19076") | ||
| public class CompositeInheritanceFailTest { | ||
|  | ||
| @Test | ||
| void hhh19076FailingTest(SessionFactoryScope scope) { | ||
| scope.inTransaction( em -> { | ||
| TestEntity e1 = new TestEntity("foo", "bar"); | ||
| em.persist(e1); | ||
|  | ||
| CompositeIdClass key = e1.getCompositeId(); | ||
| TestEntity e2 = em.find(TestEntity.class, key); | ||
| assertNotNull(e2); | ||
| } ); | ||
| } | ||
|  | ||
| @Test | ||
| void hhh19076FailingTest2(SessionFactoryScope scope) { | ||
| scope.inTransaction( em -> { | ||
| Test2Entity e1 = new Test2Entity("foo", "xxxxxx"); | ||
| em.persist(e1); | ||
|  | ||
| CompositeId2Class key = e1.getCompositeId(); | ||
| Test2Entity e2 = em.find(Test2Entity.class, key); | ||
| assertNotNull(e2); | ||
| } ); | ||
| } | ||
|  | ||
| @MappedSuperclass | ||
| public static abstract class TupAbstractEntity { | ||
| @Id | ||
| private String oid = null; | ||
|  | ||
|  | ||
| @SuppressWarnings("this-escape") | ||
| protected TupAbstractEntity() { | ||
| } | ||
|  | ||
| protected TupAbstractEntity(String oid) { | ||
| this.oid = oid; | ||
| } | ||
|  | ||
| public String getOid() { | ||
| return oid; | ||
| } | ||
|  | ||
| } | ||
|  | ||
| @Entity | ||
| public static class DummyEntity extends TupAbstractEntity { | ||
| } | ||
|  | ||
| @Entity | ||
| @IdClass(CompositeIdClass.class) | ||
| public static class TestEntity extends TupAbstractEntity { | ||
|  | ||
| @Id | ||
| private String myId; | ||
|  | ||
| protected TestEntity() { | ||
| // for JPA | ||
| } | ||
|  | ||
| public TestEntity(String oid, String myId) { | ||
| super(oid); | ||
| this.myId = myId; | ||
| } | ||
|  | ||
| public String myId() { | ||
| return myId; | ||
| } | ||
|  | ||
| public CompositeIdClass getCompositeId() { | ||
| return new CompositeIdClass(getOid(), myId); | ||
| } | ||
|  | ||
| } | ||
|  | ||
| @Entity | ||
| @IdClass(CompositeId2Class.class) | ||
| public static class Test2Entity extends TupAbstractEntity { | ||
|  | ||
| @Id | ||
| private String otherId; | ||
|  | ||
| @Version | ||
| private long tanum = 0; | ||
|  | ||
| protected Test2Entity() { | ||
| // for JPA | ||
| } | ||
|  | ||
| public Test2Entity(String oid, String otherId) { | ||
| super(oid); | ||
| this.otherId = otherId; | ||
| } | ||
|  | ||
| public String myId() { | ||
| return otherId; | ||
| } | ||
|  | ||
| public long tanum() { | ||
| return tanum; | ||
| } | ||
|  | ||
| public CompositeId2Class getCompositeId() { | ||
| return new CompositeId2Class(getOid(), otherId); | ||
| } | ||
|  | ||
| } | ||
|  | ||
| public static class CompositeIdClass { | ||
|  | ||
| private String oid; | ||
| private String myId; | ||
|  | ||
| public CompositeIdClass(String oid, String myId) { | ||
| this.oid = oid; | ||
| this.myId = myId; | ||
| } | ||
|  | ||
| public CompositeIdClass() { | ||
| } | ||
|  | ||
| public String oid() { | ||
| return oid; | ||
| } | ||
|  | ||
| public String myId() { | ||
| return myId; | ||
| } | ||
|  | ||
| } | ||
|  | ||
| public static class CompositeId2Class { | ||
|  | ||
| private String oid; | ||
| private String otherId; | ||
|  | ||
| public CompositeId2Class(String oid, String otherId) { | ||
| this.oid = oid; | ||
| this.otherId = otherId; | ||
| } | ||
|  | ||
| public CompositeId2Class() { | ||
| } | ||
|  | ||
| public String oid() { | ||
| return oid; | ||
| } | ||
|  | ||
| public String otherId() { | ||
| return otherId; | ||
| } | ||
|  | ||
| } | ||
|  | ||
| } | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The same pattern (
propertyMapping.getGetter(...).getMember()) is repeated in both identifier and version resolvers. Consider extracting this into a shared helper to reduce duplication.