apache / apache/netbeans

Insert-code for "Use Entity Manager..." does not work

Open
#3,874 0 comments 0 reactions 0 assignees View on GitHub
Java EE/Jakarta EE kind:bug needs:triage
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 13

### What happened

It is a regression of an older version (I don't remember the last version) that worked: the code inserted was not the same whether the transaction is managed by the container or by the bean.
In an EJB session, Insert Code > Unse Entity Manager..." does not insert the good code when the transaction is managed by the container (the more frequent case).
The code inserted for the method persist is

```java
@Resource
private javax.transaction.UserTransaction utx; public void persist(Object object) {
try {
utx.begin();
em.persist(object);
utx.commit();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", e);
throw new RuntimeException(e);
}
}
```

whereas it should be

```java
public void persist(Object object) {
em.persist(object);
}
```

### How to reproduce

In a new project Java with Maven > Web Application, add the provider and the jta-data-source in persistence.xml.
Then create a new Session Bean:
New > Session Bean
Check Stateless
In the body of the EJB, Insert Code > Use Entity Manager..., the bad code is inserted.

### Did this work correctly in an earlier version?

Apache NetBeans 12.3 or earlier

### Operating System

Windows 11

### JDK

11

### Apache NetBeans packaging

Apache NetBeans provided installer

### Anything else

_No response_

### Are you willing to submit a pull request?

No

### Code of Conduct

Yes

Contributor guide

Open the contributing guide

Research direction

Reproduce the regression in a Maven Web Application with a Stateless Session Bean and persistence.xml configured with a provider and JTA data source. Start at the Insert Code > Use Entity Manager action, compare generated code for container-managed and bean-managed transactions, and verify that the container-managed case no longer adds UserTransaction handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.