-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fallback to Path.getModel() if ManagedType information was erased.
ManagedType information may be erased if the attribute is declared as generic - With Hibernate 6.x for example an IllegalArgumentException is thrown. java.lang.IllegalArgumentException: Unable to locate Attribute with the given name [name] on this ManagedType [java.lang.Object] at o.h.m.model.domain.AbstractManagedType.checkNotNull(AbstractManagedType.java:225) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final] Resolves: #3274 Original Pull Request: #3375
- Loading branch information
1 parent
314dc5c
commit 225cd9b
Showing
9 changed files
with
256 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
36 changes: 36 additions & 0 deletions
36
spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/Book.java
This file contains 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,36 @@ | ||
/* | ||
* Copyright 2008-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.jpa.domain.sample; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import org.springframework.data.jpa.domain.AbstractPersistable; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
@Entity | ||
public class Book extends OwnerContainer<Owner> { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/Owner.java
This file contains 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,36 @@ | ||
/* | ||
* Copyright 2008-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.jpa.domain.sample; | ||
|
||
import jakarta.persistence.Entity; | ||
import org.springframework.data.jpa.domain.AbstractPersistable; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
@Entity | ||
public class Owner extends AbstractPersistable<Long> { | ||
|
||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
spring-data-jpa/src/test/java/org/springframework/data/jpa/domain/sample/OwnerContainer.java
This file contains 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,37 @@ | ||
/* | ||
* Copyright 2008-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.jpa.domain.sample; | ||
|
||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.MappedSuperclass; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
@MappedSuperclass | ||
public class OwnerContainer<T> { | ||
|
||
@ManyToOne | ||
T owner; | ||
|
||
public T getOwner() { | ||
return owner; | ||
} | ||
|
||
public void setOwner(T owner) { | ||
this.owner = owner; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...org/springframework/data/jpa/repository/generics/EclipseLinkGenericsIntegrationTests.java
This file contains 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,40 @@ | ||
/* | ||
* Copyright 2014-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.jpa.repository.generics; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.jpa.domain.sample.Book; | ||
import org.springframework.data.jpa.domain.sample.Owner; | ||
import org.springframework.data.jpa.repository.sample.BookRepository; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
@Transactional | ||
@ExtendWith(SpringExtension.class) | ||
@ContextConfiguration({ "classpath:eclipselink.xml", "classpath:config/namespace-application-context.xml" }) | ||
class EclipseLinkGenericsIntegrationTests extends GenericsIntegrationTests { | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
.../test/java/org/springframework/data/jpa/repository/generics/GenericsIntegrationTests.java
This file contains 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,64 @@ | ||
/* | ||
* Copyright 2014-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.jpa.repository.generics; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.jpa.domain.AbstractPersistable; | ||
import org.springframework.data.jpa.domain.sample.Book; | ||
import org.springframework.data.jpa.domain.sample.CustomAbstractPersistable; | ||
import org.springframework.data.jpa.domain.sample.Owner; | ||
import org.springframework.data.jpa.repository.sample.BookRepository; | ||
import org.springframework.data.jpa.repository.sample.CustomAbstractPersistableRepository; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
@Transactional | ||
@ExtendWith(SpringExtension.class) | ||
@ContextConfiguration(locations = { "classpath:config/namespace-autoconfig-context.xml" }) | ||
class GenericsIntegrationTests { | ||
|
||
@Autowired | ||
BookRepository repository; | ||
|
||
@Autowired | ||
EntityManager entityManager; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
Owner owner = new Owner(); | ||
owner.setName("owner"); | ||
entityManager.persist(owner); | ||
Book book = new Book(); | ||
book.setOwner(owner); | ||
entityManager.persist(book); | ||
} | ||
|
||
@Test | ||
void findAllByGenericAssociationProperty() { | ||
assertThat(repository.findAllByOwnerName("owner")).hasSize(1); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/BookRepository.java
This file contains 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,29 @@ | ||
/* | ||
* Copyright 2014-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.jpa.repository.sample; | ||
|
||
import org.springframework.data.jpa.domain.sample.Book; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Yanming Zhou | ||
*/ | ||
public interface BookRepository extends JpaRepository<Book, Long> { | ||
|
||
List<Book> findAllByOwnerName(String ownerName); | ||
} |
This file contains 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 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