persistence.xml

JPA without persistence.xml

南笙酒味 提交于 2019-11-29 22:42:12
问题 I'm trying to get started with using Guice Persist and JPA, which recommends using configuration via persistence.xml. Coming from a native Hibernate background where configuration was obtained programmatically, is there a simple way to configure a JpaPersistModule without a persistence.xml file, or will a rump persistence.xml always have to exist? If no such option exists, it might be the case where I might have to play around with PersistenceProvider (assuming the "default" parses

Is it possible to have persistence.xml in a location other than META-INF?

荒凉一梦 提交于 2019-11-29 01:50:46
I want to have my persistence.xml in conf folder of my app. How can I tell Persistence.createEntityManagerFactory that it should read it from there? The createEntityManagerFactory methods search for persistence.xml files within the META-INF directory of any CLASSPATH element. if your CLASSPATH contains the conf directory, you could place an EntityManagerFactory definition in conf/META-INF/persistence.xml If you are using EclipseLink you can set the persistence.xml location with the persistence unit property, "eclipselink.persistencexml". properties.put("eclipselink.persistencexml", "/org/acme

persistence.xml with Glassfish 3.1.1

早过忘川 提交于 2019-11-28 23:07:10
问题 I am very new to glassfish, JPA and so on and I have really problems with setting that up. What I am planning to do is a simple RESTful service with a persistent backend. I am using glassfish3 as application server and already deployed a simple REST service with the jersey-library. Now I want to provide access to a database via JPA. Glassfish is shipped with JavaDB/derby and EclipseLink, is that right? So, I want to use that :-) I created a persistence.xml in META-INF: <?xml version="1.0"

How to specify JPA 2.1 in persistence.xml?

放肆的年华 提交于 2019-11-28 17:23:37
A quick search on the net reveals 3 or 4 variants how folks have been specifying xmlns and xsi:schemaLocation in persistence.xml . What would be the 'correct' manner to specify JPA version 2.1? I'm using: <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> Andrei I According to the official documentation it must be (like yours): <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi

java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.addAnnotatedClass

半世苍凉 提交于 2019-11-28 11:29:26
问题 I am new to JPA & hibernate, when I try this tutorial . I added the following provider in my persistence.xml, <provider>org.hibernate.ejb.HibernatePersistence</provider> and I am getting this error.. log4j:WARN No appenders could be found for logger (org.jboss.logging). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.cfg

Is there a way to scan JPA entities not to declare persistent classes in a persistence.xml file?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 07:38:23
I would like to take advantage of JPA @Entity annotations not to declare class entities a J2SE persistence.xml file. What I'd like to avoid : <persistence-unit name="test" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>com.mycompany.entities.Class1</class> <class>com.mycompany.entities.Class2</class> <class>com.mycompany.entities.Class3</class> </persistence-unit> and here is what my actual persistence.xml look alike <persistence-unit name="test" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider>

Is it possible to have persistence.xml in a location other than META-INF?

眉间皱痕 提交于 2019-11-27 16:31:14
问题 I want to have my persistence.xml in conf folder of my app. How can I tell Persistence.createEntityManagerFactory that it should read it from there? 回答1: The createEntityManagerFactory methods search for persistence.xml files within the META-INF directory of any CLASSPATH element. if your CLASSPATH contains the conf directory, you could place an EntityManagerFactory definition in conf/META-INF/persistence.xml 回答2: If you are using EclipseLink you can set the persistence.xml location with the

How to specify JPA 2.1 in persistence.xml?

家住魔仙堡 提交于 2019-11-27 10:25:25
问题 A quick search on the Net reveals three or four variants how folks have been specifying xmlns and xsi:schemaLocation in persistence.xml . What would be the 'correct' manner to specify JPA version 2.1? I'm using <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> 回答1: According to the official

Changing Persistence Unit dynamically - JPA

﹥>﹥吖頭↗ 提交于 2019-11-27 07:19:53
Persistence units in persistence.xml are created during building the application. As I want to change the database url at runtime, is there any way to modify the persistence unit at runtime? I supposed to use different database other than pre-binded one after distributed. I'm using EclipseLink (JPA 2.1) N K Keep the persistence unit file (Persistence.xml) as it's. You can override the properties in it as follows. EntityManagerFactory managerFactory = null; Map<String, String> persistenceMap = new HashMap<String, String>(); persistenceMap.put("javax.persistence.jdbc.url", "<url>");

persistence.xml different transaction-type attributes

只谈情不闲聊 提交于 2019-11-27 05:56:21
In the persistence.xml JPA configuration file, you can have a line like: <persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type="JTA"> or sometimes: <persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type=”RESOURCE_LOCAL”> My question is: What is the difference between transaction-type="JTA" and transaction-type=”RESOURCE_LOCAL” ? I also noticed some persistence.xml files with the transaction-type missing. Is it correct? Defaults Default to JTA in a JavaEE environment and to RESOURCE_LOCAL in a JavaSE environment. RESOURCE_LOCAL With <persistence-unit transaction-type=