Hello. As in JPA 2 specify a different location for the persistence.xml configuration file (by default, in the META-INF folder) or specify in this file the place where to get files from the persistence-unit , where the type description is located

 <persistence-unit name="commonStorage"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>rct.gomel.drp.persistence.entities.commonstorage.CsDiagnosticResult</class> <class>rct.gomel.drp.persistence.entities.commonstorage.CsRegistrationCard</class> <properties> <property name="hibernate.connection.url" value="jdbc:sqlserver://rct-server:1433; databaseName=RCT_CommonStorage"/> ... ... ... ... 
  • I want to make a jar, where the interface of working with the database will be, and everything else, so that it is in the application using this jar. Those. a module for use in various applications within the enterprise. In other words, for the application to have only a configuration file and a .jar file with database logic. - Anton Mukhin
  • And since I only studied JPA to a certain level that allows it to be used, I would not like to learn something else for the sake of it. - Anton Mukhin

1 answer 1

Why do you need it? And where do you want to put it? Maybe it is easier to put it in the assembly where necessary, than to make a garden? As far as I know, you can put either in the META-INF of the entire application, or in META-INF inside the jar, put in the lib inside the war.

So make the configuration so that its contents can be tightly hammered into the jar. Use external connection pool in persistence.xml . Configure them separately from the application. Do not register any hosts, ports, logins, and especially passwords in persistence.xml .

  • One problem was solved, but what about the @Entity @Entity that users will have to implement? @ cy6erGn0m, convert your comments in response. - Anton Mukhin
  • No Let them implement them. The main thing is that at the moment of launching the context the corresponding classes are visible to the container. - cy6erGn0m