'Is there a way to get the EntityManagerFactory on a project that uses Java Spring JPA but doesn't have a "persistence.xml" file?
I want to use the EMF to do queries constructed at runtime on a String. If there is a way I would appreciate it if someone could tell me how and give a small example. Yes, I have read the Spring Data JPA Documentation about Specifications to do custom queries but that is not what I am looking for. The project doesn't have persistence units defined, instead it has inside the spring folder an application-config.xml file which in turn references the file persistence-config.xml and inside there is a bean that is like this:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${db.drive_class}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="maxActive" value="30" />
<property name ="maxWait" value ="50000"/>
<property name = "testWhileIdle" value = "true" />
<property name = "validationQuery" value = "select 1 from dual" />
<property name = "testOnBorrow" value = "true" />
<property name = "timeBetweenEvictionRunsMillis" value = "50000" />
</bean>
That's why solutions that suggest using an EntityManager created from a Factory from a Persistence Unit haven't worked for me since this project doesn't work with that.
Solution 1:[1]
If I understand your question correctly, you just want to know how to practice with a small spring/spring-boot project with JPA supported.
I just suggest you download the spring-boot project related source code with samples.
If you have time: https://github.com/ityouknow/spring-boot-examples/tree/master/spring-boot-jpa can be a reference. You can download the project, read the source code and debug it. The code is enough for understanding/matching on the JPA document you've read.
And https://www.baeldung.com/spring-boot-h2-database In this site, there are many related articles to introduce the spring/spring-boot related guides.
Hope it can help you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | SeanH |