0

Does Seam support multiple persistence units in its configuration? Also, when would you want to have or need multiple persistence units?

I am working on a generic component and right now, it only supports a single persistence unit which makes sense to me as I have never used more than 1 persistence unit per web application. So, I am having difficulty seeing where you would use more than a single persistence unit.

Thanks,

Walter

4

2 に答える 2

1

Does Seam support multiple persistence units in its configuration?

I don't see why it wouldn't. Configure several persistence units and get them injected by name:

@PersistenceContext(unitName="UNITNAME")
private EntityManager em;

Also, when would you want to have or need multiple persistence units?

If you need to access multiples datasources.

于 2010-06-24T03:32:29.337 に答える
0

It's very well possible to have multiple persistence units in JPA and in JPA with Seam. In Seam it's very easy. Just create more than one <persistence-unit name="myapp" /> elements in your persistence.xml and configure an EntityManagerFactory for each unit, and optionally an EntityManager for each EntityManagerFactory. You can then simply inject any EntityManager in the standard way:

@In
EntityManager entityManagerOne;

where your EntityManager is named entityManagerOne (and the other entityManagerTwo).

The most important reason to have multiple persistence units is the requirement to work with multiple database systems. This is not related to a data source, but the issue is simply to define a scope for your entity mappings.

Another reason is that you choose a transaction strategy (global (JTA) or local (resource-local)) per persitence unit. So, if you need to work with multiple transaction strategies you can create 2 persistence units for the same database.

于 2010-08-05T16:02:33.257 に答える