-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19257 - Introduce @EmbeddedTable #11059
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,49 @@ | ||||||
/* | ||||||
* SPDX-License-Identifier: Apache-2.0 | ||||||
* Copyright Red Hat Inc. and Hibernate Authors | ||||||
*/ | ||||||
package org.hibernate.annotations; | ||||||
|
||||||
import org.hibernate.Incubating; | ||||||
|
||||||
import java.lang.annotation.Target; | ||||||
import java.lang.annotation.Retention; | ||||||
|
||||||
import static java.lang.annotation.ElementType.FIELD; | ||||||
import static java.lang.annotation.ElementType.METHOD; | ||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||||||
|
||||||
/** | ||||||
* Allows an easier mechanism to declare the table to which an embedded value | ||||||
* maps compared to the Jakarta Persistence compliant mechanism requiring | ||||||
* multiple {@link jakarta.persistence.AttributeOverride} | ||||||
* and {@link jakarta.persistence.AssociationOverride} annotations. | ||||||
* <pre> | ||||||
* @Entity | ||||||
* @Table(name="primary") | ||||||
* @SecondaryTable(name="secondary") | ||||||
* class Person { | ||||||
* ... | ||||||
* @Embedded | ||||||
* @EmbeddedTable("secondary") | ||||||
* Address address; | ||||||
* } | ||||||
* </pre> | ||||||
* | ||||||
* @apiNote Only supported for the embedded defined on an entity or mapped-superclass; all other (mis)uses | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* will lead to a {@linkplain org.hibernate.boot.models.AnnotationPlacementException}. | ||||||
* | ||||||
* @see EmbeddedColumnNaming | ||||||
* | ||||||
* @since 7.2 | ||||||
* @author Steve Ebersole | ||||||
*/ | ||||||
@Target({METHOD, FIELD}) | ||||||
@Retention(RUNTIME) | ||||||
@Incubating | ||||||
public @interface EmbeddedTable { | ||||||
/** | ||||||
* The name of the table in which the embedded value is stored. | ||||||
*/ | ||||||
String value(); | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.boot.models.annotations.internal; | ||
|
||
import org.hibernate.annotations.EmbeddedTable; | ||
import org.hibernate.models.spi.ModelsContext; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Steve Ebersole | ||
*/ | ||
@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) | ||
public class EmbeddedTableAnnotation implements EmbeddedTable { | ||
private String value; | ||
|
||
/** | ||
* Used in creating dynamic annotation instances (e.g. from XML) | ||
*/ | ||
public EmbeddedTableAnnotation(ModelsContext modelContext) { | ||
Check noticeCode scanning / CodeQL Useless parameter Note
The parameter 'modelContext' is never used.
|
||
} | ||
|
||
/** | ||
* Used in creating annotation instances from JDK variant | ||
*/ | ||
public EmbeddedTableAnnotation( | ||
EmbeddedTable annotation, | ||
ModelsContext modelContext) { | ||
Check noticeCode scanning / CodeQL Useless parameter Note
The parameter 'modelContext' is never used.
|
||
this.value = annotation.value(); | ||
} | ||
|
||
/** | ||
* Used in creating annotation instances from Jandex variant | ||
*/ | ||
public EmbeddedTableAnnotation( | ||
Map<String, Object> attributeValues, | ||
ModelsContext modelContext) { | ||
Check noticeCode scanning / CodeQL Useless parameter Note
The parameter 'modelContext' is never used.
|
||
this.value = (String) attributeValues.get( "value" ); | ||
} | ||
|
||
@Override | ||
public Class<? extends Annotation> annotationType() { | ||
return EmbeddedTable.class; | ||
} | ||
|
||
@Override | ||
public String value() { | ||
return value; | ||
} | ||
|
||
public void value(String value) { | ||
this.value = value; | ||
} | ||
} |
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.