-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Fix for Jira issue HHH-16261 #6345
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
7 commits
Select commit
Hold shift + click to select a range
5648431
HHH-16261 - Test case for HHH-16261
cigaly 1a606a4
HHH-16261 - Check if address field has been generated in Author_ class
cigaly 61b006e
HHH-16261 - More strict test case
cigaly d9f3f02
HHH-16261 - Not ignoring JDK 14 records when processing
cigaly 232d113
HHH-16261 - Fixed formatting
cigaly 6ffee2e
HHH-16261 - Avoid explicit use of ElementKind.RECORD to make code com…
cigaly 0ede37a
HHH-16261 - Change Gradle build script to allow separate builds using…
cigaly 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
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
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
7 changes: 7 additions & 0 deletions
7
...ing/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/records/Address.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,7 @@ | ||
package org.hibernate.jpamodelgen.test.records; | ||
|
||
import jakarta.persistence.Embeddable; | ||
|
||
@Embeddable | ||
public record Address(String street, String city, String postalCode) { | ||
} |
53 changes: 53 additions & 0 deletions
53
tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/records/Author.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,53 @@ | ||
package org.hibernate.jpamodelgen.test.records; | ||
|
||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
public class Author { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@Embedded | ||
private Address address; | ||
|
||
private String firstName; | ||
|
||
private String lastName; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public Address getAddress() { | ||
return address; | ||
} | ||
|
||
public void setAddress(Address address) { | ||
this.address = address; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...del-generator/src/test/java/org/hibernate/jpamodelgen/test/records/Java14RecordsTest.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,52 @@ | ||
package org.hibernate.jpamodelgen.test.records; | ||
|
||
import jakarta.persistence.metamodel.SingularAttribute; | ||
import org.hibernate.jpamodelgen.test.util.CompilationTest; | ||
import org.hibernate.jpamodelgen.test.util.TestForIssue; | ||
import org.hibernate.jpamodelgen.test.util.WithClasses; | ||
import org.junit.Test; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.ParameterizedType; | ||
import java.lang.reflect.Type; | ||
import java.util.List; | ||
|
||
import static java.lang.reflect.Modifier.isStatic; | ||
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor; | ||
import static org.hibernate.jpamodelgen.test.util.TestUtil.getFieldFromMetamodelFor; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
public class Java14RecordsTest extends CompilationTest { | ||
|
||
@Test | ||
@TestForIssue(jiraKey = "HHH-16261") | ||
@WithClasses({Address.class, Author.class}) | ||
public void testEmbeddableRecordProperty() { | ||
assertMetamodelClassGeneratedFor(Address.class); | ||
for (final String fieldName : List.of("street", "city", "postalCode")) { | ||
assertNotNull("Address must contain '" + fieldName + "' field", getFieldFromMetamodelFor(Address.class, fieldName)); | ||
} | ||
assertMetamodelClassGeneratedFor(Author.class); | ||
|
||
final Field addressField = getFieldFromMetamodelFor(Author.class, "address"); | ||
assertNotNull("Author must contain 'address' field", addressField); | ||
assertTrue(isStatic(addressField.getModifiers())); | ||
if (addressField.getGenericType() instanceof ParameterizedType parameterizedType) { | ||
assertEquals(SingularAttribute.class, parameterizedType.getRawType()); | ||
final Type[] typeArguments = parameterizedType.getActualTypeArguments(); | ||
assertEquals(2, typeArguments.length); | ||
assertEquals(Author.class, typeArguments[0]); | ||
assertEquals(Address.class, typeArguments[1]); | ||
} else { | ||
fail("Address field must be instance of ParameterizedType"); | ||
} | ||
|
||
final Field addressNameField = getFieldFromMetamodelFor(Author.class, "address".toUpperCase()); | ||
assertNotNull("Author must contain 'ADDRESS' field", addressNameField); | ||
assertTrue(isStatic(addressNameField.getModifiers())); | ||
assertEquals(String.class, addressNameField.getGenericType()); | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.