| .. | .. |
|---|
| 45 | 45 | log.info("EntityManagerFactory initialized correctly: {}", entityManagerFactory); |
|---|
| 46 | 46 | } catch (Exception e) { |
|---|
| 47 | 47 | log.error("Error creating EntityManagerFactory for persistence unit 'localdb'", e); |
|---|
| 48 | | - entityManagerFactory = null; |
|---|
| 48 | + throw new IllegalStateException("Could not initialize EntityManagerFactory", e); |
|---|
| 49 | 49 | } |
|---|
| 50 | 50 | } |
|---|
| 51 | 51 | |
|---|
| .. | .. |
|---|
| 56 | 56 | * @return a new EntityManager; caller must close it |
|---|
| 57 | 57 | */ |
|---|
| 58 | 58 | public EntityManager getEntityManager() { |
|---|
| 59 | | - try { |
|---|
| 60 | | - if (entityManagerFactory == null) { |
|---|
| 61 | | - log.error("EntityManagerFactory is null"); |
|---|
| 62 | | - return null; |
|---|
| 63 | | - } |
|---|
| 64 | | - EntityManager em = entityManagerFactory.createEntityManager(); |
|---|
| 65 | | - log.info("Created EntityManager: {}", em); |
|---|
| 66 | | - return em; |
|---|
| 67 | | - } catch (Exception e) { |
|---|
| 68 | | - log.error("Error creating EntityManager", e); |
|---|
| 69 | | - return null; |
|---|
| 59 | + if (entityManagerFactory == null) { |
|---|
| 60 | + throw new IllegalStateException("EntityManagerFactory is null"); |
|---|
| 70 | 61 | } |
|---|
| 62 | + EntityManager em = entityManagerFactory.createEntityManager(); |
|---|
| 63 | + log.info("Created EntityManager: {}", em); |
|---|
| 64 | + return em; |
|---|
| 71 | 65 | } |
|---|
| 72 | 66 | } |
|---|