rave
rave

Reputation:

JPA default persistence unit

I get exception "There is no default persistence unit in this deployment." can I somehow mark unit as default?(I have only one persistence unit, so Id rather not call it by name)

Upvotes: 2

Views: 6104

Answers (2)

Archimedes Trajano
Archimedes Trajano

Reputation: 41220

You are probably doing it through code rather than letting the container manage it. In which case you have to specify by name.

My unit test code has this code block to do this.

@Before
public void createEntityManagerFactory() throws IOException {
    final Properties p = new Properties();
    p.load(getClass().getResourceAsStream("/inmemory.properties"));
    emf = Persistence.createEntityManagerFactory("default", p);
}

However, my application code looks like this.

/**
 * Injected persistence context.
 */
@PersistenceContext
private EntityManager em;

Upvotes: 1

Jim Barrows
Jim Barrows

Reputation: 3634

No, you have to call PU's by name.

Upvotes: 1

Related Questions