Skip to content
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

The type of a Map field where the key is of type Object should result as resolved #56

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
package org.hibernate.models.internal;

import java.util.List;
import java.util.Objects;

import org.hibernate.models.spi.ArrayTypeDetails;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassTypeDetails;
import org.hibernate.models.spi.ParameterizedTypeDetails;
import org.hibernate.models.spi.PrimitiveTypeDetails;
Expand Down Expand Up @@ -63,7 +61,7 @@ public Boolean caseParameterizedType(
SourceModelBuildingContext buildingContext) {
final List<TypeDetails> typeArgs = parameterizedType.getArguments();
for ( TypeDetails arg : typeArgs ) {
if ( !isBound( arg, buildingContext ) ) {
if ( !arg.isResolved() ) {
return false;
}
}
Expand Down
87 changes: 87 additions & 0 deletions src/test/java/org/hibernate/models/annotations/MapKeyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.hibernate.models.annotations;

import java.util.Date;
import java.util.Map;

import org.hibernate.models.SourceModelTestHelper;
import org.hibernate.models.internal.SourceModelBuildingContextImpl;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.FieldDetails;
import org.hibernate.models.spi.TypeDetails;

import org.junit.jupiter.api.Test;

import org.jboss.jandex.Index;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.MapKeyClass;
import jakarta.persistence.MapKeyColumn;
import jakarta.persistence.MapKeyTemporal;
import jakarta.persistence.OneToMany;
import jakarta.persistence.TemporalType;

import static org.assertj.core.api.Assertions.assertThat;

public class MapKeyTest {

@Test
void testWithJandex() {
final Index index = SourceModelTestHelper.buildJandexIndex(
School.class,
Person.class
);
testFieldsAreResolved( index );
}

@Test
void testWithoutJandex() {
testFieldsAreResolved( null );
}

void testFieldsAreResolved(Index index) {
final SourceModelBuildingContextImpl buildingContext = SourceModelTestHelper.createBuildingContext(
index,
School.class,
Person.class
);

final ClassDetails schoolClassDetails = buildingContext.getClassDetailsRegistry().getClassDetails( School.class.getName() );

final FieldDetails idField = schoolClassDetails.findFieldByName( "id" );
final TypeDetails idFieldType = idField.getType();
assertThat( idFieldType.isResolved() ).isTrue();

FieldDetails mapKeyField = schoolClassDetails.findFieldByName( "studentsByDate" );
TypeDetails typeDetails = mapKeyField.resolveRelativeType( schoolClassDetails );
assertThat( typeDetails.isResolved() ).isTrue();

FieldDetails mapKeyField2 = schoolClassDetails.findFieldByName( "teachersByDate" );
TypeDetails typeDetails2 = mapKeyField2.resolveRelativeType( schoolClassDetails );
assertThat( typeDetails2.isResolved() ).isFalse();
}

@Entity
public static class School<T> {
@Id
private int id;

@OneToMany(mappedBy = "school")
@MapKeyClass(Date.class)
@MapKeyColumn(name = "THE_DATE")
@MapKeyTemporal(TemporalType.DATE)
private Map<Object, Person> studentsByDate;

@OneToMany(mappedBy = "school")
@MapKeyClass(Date.class)
@MapKeyColumn(name = "THE_DATE")
@MapKeyTemporal(TemporalType.DATE)
private Map<T, Person> teachersByDate;
}

@Entity
public static class Person {
@Id
private int id;
}
}
Loading