Skip to content

Commit b181eec

Browse files
dreab8sebersole
authored andcommitted
HHH-18195 migration guide
1 parent e67967a commit b181eec

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

migration-guide.adoc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,60 @@ String isDefault();
144144
* Removed `MetadataContributor`, deprecated in favor of `AdditionalMappingContributor`
145145
* Removed `@Persister`.
146146
* Removed `hibernate.mapping.precedence` and friends
147+
* Removed `org.hibernate.Session#save(Object object)` and `org.hibernate.Session#save(String entityName, Object object)` in favor of `org.hibernate.Session#persist(Object object)` and `org.hibernate.Session#persist(String entityName, Object object)`
148+
* Removed `org.hibernate.Session#saveOrUpdate(Object object)` and `org.hibernate.Session#saveOrUpdate(String entityName, Object object)` in favor `persist` if the entity is transient or `merge` if the entity is detached.
149+
* Removed `org.hibernate.Session#update(Object object` and `org.hibernate.Session#update(String entityName, Object object)` in favor of `org.hibernate.Session.merge(T object)` and `org.hibernate.Session.merge(String entityName, T object)`
150+
* Removed `org.hibernate.annotations.CascadeType.SAVE_UPDATE` in favor of `org.hibernate.annotations.CascadeType.PERSIST` + `org.hibernate.annotations.CascadeType.MERGE`
151+
* Removed `@SelectBeforeUpdate`
152+
153+
[WARNING]
154+
===
155+
The removal of `CascadeType.SAVE_UPDATE` slightly changes the persist and flush behaviour (not affecting application using `Entitymanager`) that now conforms with the Jakarta JPA specifications.
156+
157+
Persisting a transient entity with an associated detached entity where the association is annotated with cascade=all or cascade=persist throws an exception if the detached entity has not been re-associated with the the session using lock or merge.
158+
159+
The same happens when flushing a managed entity having an associated detached entity.
160+
161+
```
162+
@Entit
163+
class Parent {
164+
...
165+
166+
@OneToMany(cascade = CascadeType.ALL, mappedBy = "parent", orphanRemoval = true)
167+
@LazyCollection(value = LazyCollectionOption.EXTRA)
168+
private Set<Child> children = new HashSet<>();
169+
}
170+
171+
@Entity
172+
class Child {
173+
174+
...
175+
176+
@Id
177+
@GeneratedValue(strategy = GenerationType.AUTO)
178+
private Long id;
179+
180+
@ManyToOne
181+
private Parent parent;
182+
}
183+
184+
185+
```
186+
187+
```
188+
// Being Child c1 detached.
189+
190+
scope.inTransaction(
191+
session -> {
192+
Parent parent = session.get( Parent.class, parentId );
193+
// add detached Child c
194+
parent.addChild( c1 );
195+
}
196+
);
197+
```
198+
will throw an `jakarta.persistence.EntityExistsException`
199+
200+
in order to fix the issue we can call `session.lock(c1,LockMode.NONE)` before adding `c1` to the `parent` or instead using `p.addChild( session.merge(c1) )`;
147201

148202

149203
[[ddl-implicit-datatype-timestamp]]

0 commit comments

Comments
 (0)