-
Notifications
You must be signed in to change notification settings - Fork 73
alternatives to ManagedEntityMode #820
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
f9143da
bd91a93
178d135
556e730
3d53674
5b10339
ed0276a
15e0188
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,65 @@ | ||
| /* | ||
| * Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License v. 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0, | ||
| * or the Eclipse Distribution License v. 1.0 which is available at | ||
| * http://www.eclipse.org/org/documents/edl-v10.php. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
| */ | ||
|
|
||
| // Contributors: | ||
| // Gavin King - 4.0 | ||
|
|
||
| package jakarta.persistence; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import static java.lang.annotation.ElementType.TYPE; | ||
| import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
|
||
| /** | ||
| * Specifies that the annotated entity class is read-only, | ||
| * meaning that mutations to its fields and properties are | ||
| * not normally made persistent. | ||
| * <p> | ||
| * If an instance of a read-only entity is modified while | ||
| * the instance is in the managed state and associated with | ||
| * a persistence context, the behavior is undefined. Such | ||
| * modifications might be lost; they might be made persistent; | ||
| * or the provider might throw an exception. Portable | ||
| * applications should not depend on such provider-specific | ||
| * behavior. | ||
| * <p> | ||
| * Many write operations are permitted for read-only entities. | ||
| * A new instance of a read-only entity may be made persistent | ||
| * by calling {@link EntityManager#persist}. A managed instance | ||
| * may be removed by calling {@link EntityManager#remove}. And | ||
| * a new or detached instance may be passed to any appropriate | ||
| * operation of {@link EntityAgent}, including {@code insert()}, | ||
| * {@code update()}, {@code upsert()}, and {@code delete()}. | ||
| * <p> | ||
| * The effect of this annotation may be selectively disabled | ||
| * for a given managed instance of a read-only entity class by | ||
| * passing the instance to {@link EntityManager#enableFlush}. | ||
| * The {@link ReadOnly} annotation has no effect at all on an | ||
| * {@code EntityAgent}. | ||
| * <p> | ||
| * The provider is not required to detect modifications to | ||
| * read-only entities and is encouraged to avoid tracking | ||
| * the state of read-only entities whenever it might result | ||
| * in a significant cost to performance. | ||
| * | ||
| * @see EntityManager#enableFlush(Object) | ||
| * | ||
| * @since 4.0 | ||
| */ | ||
| @Documented | ||
| @Target(TYPE) | ||
| @Retention(RUNTIME) | ||
| public @interface ReadOnly { | ||
|
Contributor
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. Given this definition, I think the name
Member
Author
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.
I .... guess I don't find that very odd? It's perhaps slightly odd to say that you can delete a read-only thing, but I don't see how it's strange to say that you can create one.
"Immutable" to me implies a much higher level of un-modifiability than "read only". When I say something is "immutable", I usually mean in some sort of Platonic sense. Not just in the sense of "I'm not interested in modifying this thing".
Member
Author
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. By the way, I consdered calling it |
||
| } | ||
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.
AFAIU, in Hibernate ORM it's impossible to make
@Immutableentities non-read-only, so I would rather not do this. Also seeorg.hibernate.engine.internal.AbstractEntityEntry#setReadOnly.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.
What exists in Hibernate today grew organically and it shows. I don't think it's an especially perfect model.