-
-
Couldn't load subscription status.
- Fork 3.7k
HHH 14241 Support ImplicitNamingStrategyComponentPathImpl with IdClass #3583
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
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
50 changes: 50 additions & 0 deletions
50
hibernate-core/src/test/java/org/hibernate/id/idclass/IdClassNamingStrategyTest.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,50 @@ | ||
| /* | ||
| * Hibernate, Relational Persistence for Idiomatic Java | ||
| * | ||
| * License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
| * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
| */ | ||
| package org.hibernate.id.idclass; | ||
|
|
||
| import org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl; | ||
| import org.hibernate.cfg.Configuration; | ||
|
|
||
| import org.hibernate.testing.TestForIssue; | ||
| import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; | ||
| import org.junit.Test; | ||
|
|
||
| public class IdClassNamingStrategyTest extends BaseCoreFunctionalTestCase { | ||
|
|
||
| @Override | ||
| protected Class<?>[] getAnnotatedClasses() { | ||
| return new Class<?>[] { MyEntity.class }; | ||
| } | ||
|
|
||
| @Override | ||
| protected void configure(Configuration configuration) { | ||
| /* | ||
| * With this implicit naming strategy, we got the following mapping: | ||
| * | ||
| * create table MyEntity ( | ||
| * id_idA bigint not null, | ||
| * id_idB bigint not null, | ||
| * _identifierMapper_idA bigint not null, <-- ?? | ||
| * _identifierMapper_idB bigint not null, <-- ?? | ||
| * notes varchar(255), | ||
| * primary key (id_idA, id_idB) | ||
| * ) | ||
| */ | ||
| configuration.setImplicitNamingStrategy( new ImplicitNamingStrategyComponentPathImpl() ); | ||
jrenaat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Test | ||
| @TestForIssue(jiraKey = "HHH-14241") | ||
| public void test() { | ||
jrenaat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| inTransaction( ( session ) -> { | ||
| MyEntity entity = new MyEntity(); | ||
| entity.setId( new MyEntityId( 739L, 777L ) ); | ||
|
|
||
| session.persist( entity ); | ||
| } ); | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
hibernate-core/src/test/java/org/hibernate/id/idclass/MyEntity.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,41 @@ | ||
| /* | ||
| * Hibernate, Relational Persistence for Idiomatic Java | ||
| * | ||
| * License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
| * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
| */ | ||
| package org.hibernate.id.idclass; | ||
|
|
||
| import javax.persistence.Entity; | ||
| import javax.persistence.Id; | ||
| import javax.persistence.IdClass; | ||
|
|
||
| @Entity | ||
| @IdClass( MyEntityId.class ) | ||
| public class MyEntity { | ||
|
|
||
| @Id | ||
| private Long idA; | ||
|
|
||
| @Id | ||
| private Long idB; | ||
|
|
||
| private String notes; | ||
|
|
||
| public MyEntityId getId() { | ||
| return new MyEntityId( idA, idB ); | ||
| } | ||
|
|
||
| public void setId(MyEntityId id) { | ||
| this.idA = id.getIdA(); | ||
| this.idB = id.getIdB(); | ||
| } | ||
|
|
||
| public String getNotes() { | ||
| return notes; | ||
| } | ||
|
|
||
| public void setNotes(String notes) { | ||
| this.notes = notes; | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
hibernate-core/src/test/java/org/hibernate/id/idclass/MyEntityId.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,58 @@ | ||
| /* | ||
| * Hibernate, Relational Persistence for Idiomatic Java | ||
| * | ||
| * License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
| * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
| */ | ||
| package org.hibernate.id.idclass; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.Objects; | ||
|
|
||
| public class MyEntityId implements Serializable { | ||
jrenaat marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private Long idA; | ||
| private Long idB; | ||
|
|
||
| public MyEntityId(Long generatedId, Long providedId) { | ||
| this.idA = generatedId; | ||
| this.idB = providedId; | ||
| } | ||
|
|
||
| private MyEntityId() { | ||
| } | ||
|
|
||
| public Long getIdA() { | ||
| return idA; | ||
| } | ||
|
|
||
| public void setIdA(Long idA) { | ||
| this.idA = idA; | ||
| } | ||
|
|
||
| public Long getIdB() { | ||
| return idB; | ||
| } | ||
|
|
||
| public void setIdB(Long idB) { | ||
| this.idB = idB; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if ( this == o ) { | ||
| return true; | ||
| } | ||
| if ( o == null || getClass() != o.getClass() ) { | ||
| return false; | ||
| } | ||
| MyEntityId pk = (MyEntityId) o; | ||
| return Objects.equals( idA, pk.idA ) && | ||
| Objects.equals( idB, pk.idB ); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash( idA, idB ); | ||
| } | ||
| } | ||
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.