|
1 | 1 | package com.fasterxml.jackson.datatype.hibernate5;
|
2 | 2 |
|
3 |
| -import javax.persistence.ElementCollection; |
4 |
| -import javax.persistence.EntityManager; |
5 |
| -import javax.persistence.FetchType; |
6 |
| -import javax.persistence.ManyToMany; |
7 |
| -import javax.persistence.ManyToOne; |
8 |
| -import javax.persistence.OneToMany; |
9 |
| -import javax.persistence.OneToOne; |
| 3 | +import javax.persistence.*; |
10 | 4 | import java.io.IOException;
|
11 |
| -import java.util.ArrayList; |
12 |
| -import java.util.Collection; |
13 |
| -import java.util.HashMap; |
14 |
| -import java.util.HashSet; |
15 |
| -import java.util.List; |
16 |
| -import java.util.Map; |
17 |
| -import java.util.Set; |
| 5 | +import java.util.*; |
18 | 6 |
|
19 | 7 | import com.fasterxml.jackson.core.JsonGenerator;
|
20 |
| -import com.fasterxml.jackson.databind.BeanProperty; |
21 |
| -import com.fasterxml.jackson.databind.JavaType; |
22 |
| -import com.fasterxml.jackson.databind.JsonMappingException; |
23 |
| -import com.fasterxml.jackson.databind.JsonSerializer; |
24 |
| -import com.fasterxml.jackson.databind.SerializerProvider; |
| 8 | +import com.fasterxml.jackson.databind.*; |
25 | 9 | import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
|
26 | 10 | import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
27 | 11 | import com.fasterxml.jackson.databind.ser.ContainerSerializer;
|
28 | 12 | import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
29 | 13 | import com.fasterxml.jackson.databind.ser.ResolvableSerializer;
|
30 | 14 | import com.fasterxml.jackson.databind.util.NameTransformer;
|
31 | 15 | import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module.Feature;
|
| 16 | + |
32 | 17 | import org.hibernate.FlushMode;
|
33 | 18 | import org.hibernate.Hibernate;
|
34 | 19 | import org.hibernate.Session;
|
|
38 | 23 | import org.hibernate.engine.spi.SessionFactoryImplementor;
|
39 | 24 | import org.hibernate.engine.spi.SessionImplementor;
|
40 | 25 | import org.hibernate.mapping.Bag;
|
41 |
| -import org.hibernate.resource.transaction.TransactionCoordinator; |
42 | 26 | import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl;
|
43 | 27 |
|
44 | 28 | /**
|
@@ -421,26 +405,23 @@ protected static class SessionReader
|
421 | 405 | {
|
422 | 406 | public static boolean isJTA(Session session)
|
423 | 407 | {
|
424 |
| - if (session instanceof EntityManager) |
425 |
| - { |
426 |
| - try |
427 |
| - { |
| 408 | + if (session instanceof EntityManager) { |
| 409 | + try { |
428 | 410 | session.getTransaction();
|
429 | 411 | return false;
|
430 |
| - } |
431 |
| - catch (final IllegalStateException e) |
432 |
| - { |
| 412 | + } catch (final IllegalStateException e) { |
433 | 413 | // EntityManager is required to throw an IllegalStateException if it's JTA-managed
|
434 | 414 | return true;
|
435 | 415 | }
|
436 | 416 | }
|
437 |
| - else if (session instanceof SessionImplementor) |
438 |
| - { |
439 |
| - final TransactionCoordinator transactionCoordinator = ((SessionImplementor) session).getTransactionCoordinator(); |
440 |
| - |
| 417 | + if (session instanceof SessionImplementor) { |
| 418 | + // 23-Aug-2018, tatu: Unfortunately, Hibernate ORM has a pretty severe backwards-compatibility |
| 419 | + // breakage between 5.1 and 5.2, due to move of `TransactionCoordinator` being moved to |
| 420 | + // different package. As such, we can not cast it... and it's unclear if even calling the |
| 421 | + // method directly is kosher. |
| 422 | + final Object transactionCoordinator = ((SessionImplementor) session).getTransactionCoordinator(); |
441 | 423 | return (transactionCoordinator instanceof JtaTransactionCoordinatorImpl);
|
442 | 424 | }
|
443 |
| - |
444 | 425 | // If in doubt, do without (transaction)
|
445 | 426 | return true;
|
446 | 427 | }
|
|
0 commit comments