Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow full configuration of EntityManagerFactory without persistence.xml #114

Closed
lukasj opened this issue Aug 28, 2015 · 7 comments
Closed

Comments

@lukasj
Copy link
Contributor

lukasj commented Aug 28, 2015

I'd like to be able to register classes, set a persistence provider, and also add packages to scan (bonus).

In addition, I don't think persistence unit name should be required-at least an exception shouldn't be thrown if no persistence.xml is found or no persistence unit with the name is found.

My end-goal is an hk2 factory, in the JAX-RS context (https://jersey.java.net/documentation/latest/ioc.html) that can be instantiated with a JDBC url, username, password, and package names to scan, and then bound to EntityManager for injection. Without the ability to configure the classes that an entity manager factory loads, this is difficult (requires a persistence xml in the project that uses the factory)

@lukasj
Copy link
Contributor Author

lukasj commented Aug 28, 2015

@glassfishrobot Commented
Reported by moodysalem

@lukasj
Copy link
Contributor Author

lukasj commented Dec 10, 2015

@glassfishrobot Commented
kalgon said:
Can't you just create your own javax.persistence.spi.PersistenceUnitInfo and do something like this to begin with? (no package scanning)

for (PersistenceProvider provider : PersistenceProviderResolverHolder.getPersistenceProviderResolver().getPersistenceProviders()) {
	return provider.createContainerEntityManagerFactory(persistenceUnifInfo, properties);
}

@lukasj
Copy link
Contributor Author

lukasj commented Apr 9, 2016

@glassfishrobot Commented
ondrejm said:
The above piece of code is great stuff, it's a pity almost noone knows that something like this is possible.
Though, I'd welcome more declarative way that makes it possible to combine with @PersistenceUnit, which everybody knows how to use.

Something like having a CDI producer with methods marked with @PersistenceUnitDefinition qualifier:

public class PersisteneConfig {
  @Produces
  @PersistenceUnitDefinition(name = "puMain")
  public PersistenceUnitInfo puMainInfo() {
    return persistenceUnitInfo;
  }

  @Produces
  @PersistenceUnitDefinition(name = "puMain")
  public Map puMainProperties() {
    return properties;
  }
}

If CDI producer would be too late in the lifecycle, or dependency on CDI is not convenient, than some kind of listener executed soon enough in the lifecycle.

@lukasj
Copy link
Contributor Author

lukasj commented May 5, 2017

@glassfishrobot Commented
This issue was imported from java.net JIRA JPA_SPEC-114

@lukasj
Copy link
Contributor Author

lukasj commented Aug 31, 2018

@m-reza-rahman
Copy link

I think this needs a bit more justification. Isn't the JPA SPI doing all this for example for the Spring world? Maybe this should just be closed to reduce clutter or marked as very low priority so the focus can be on higher impact work?

Reza Rahman
Jakarta EE Ambassador, Author, Blogger, Speaker

Please note views expressed here are my own as an individual community member and do not reflect the views of my employer.

gavinking added a commit to gavinking/persistence that referenced this issue Aug 13, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Aug 13, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Aug 13, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Aug 21, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Aug 21, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Aug 21, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Aug 21, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Aug 21, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Aug 21, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Aug 21, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Aug 21, 2023
gavinking added a commit to gavinking/persistence that referenced this issue Aug 21, 2023
lukasj pushed a commit that referenced this issue Aug 21, 2023
@gavinking
Copy link
Contributor

This was done by #465.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants