I have created the OSGI bundle project with JPA 2.0 support. I am using OpenJpa as a JPA provider. when I run the bundle, I Could not create OpenJPAEntityManagerFactory. Please fine the code which I used to create OpenJPAEntityManagerFactory.
OpenJPAEntityManagerFactory emf = OpenJPAPersistence.createEntityManagerFactory(
"StudentServiceProvider",
"META-INF/persistence.xml");
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="StudentServiceProvider">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>com.student.serviceprovider.model.Student</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/NYL" />
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionUserName" value="root" />
<property name="openjpa.ConnectionPassword" value="root" />
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
<!-- To avoid foreign key issues -->
<property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)" />
<!-- Auto create tables -->
<property name="jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
</properties>
</persistence-unit>
</persistence>
In src folder I have META-INF and i created the persistence.xml with in that(META-INF/persistennce.xml).
Please let me know to resolve this issue.
It'd probably be helpful if you listed what the error is you are getting, but it might be because you have this line twice:
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
This is just a stab in the dark since you don't mention what the error is and I just happen to be getting an error message of "Equivalent property keys "openjpa.Log" and "Log" are specified in configuration." for something I'm working on.
Related
I have simple problem. When I edit something directly in database for example by UPDATE statement I can't see any changes in my application. I read somewhere that this is reason of Hibernate cache or am wrong ?
My hibernate configuration looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="transactionPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/TestTable?UseUnicode=true&characterEncoding=utf8" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="uberSecretUsername" />
<property name="hibernate.connection.password" value="uberSecretPassword" />
<property name="show_sql" value="true" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
<property name="hibernate.connection.charSet" value="UTF-8" />
</properties>
</persistence-unit>
</persistence>
Its pretty basic nothing here that can surprise you. How can I disable this cache or how can I get this working. I just want simple see changes in app when I make changes directly on database
I am using the following JPA code with MySQL DB and OpenJPA 2.2.2:
#MappedSuperclass
public abstract class IdentifiableEntity implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
// getters, setters, etc.
}
#Entity
public class User extends IdentifiableEntity {
private String name;
// getters, setters, etc.
}
I get this message when doing User user = new User(); in JSE environment:
ERROR [main] openjpa.Enhance - The identity field defined in the
IdentifiableEntity Embeddable is not supported.
I tried running with the OpenJPA dynamically loaded class enhancer on Oracle 1.6 JDK. The code seems to be executing correctly in spite of the message.
Why am I getting this message? Is it benign?
Here are the contents of persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="persistenceUnit">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<properties>
<property name="openjpa.ConnectionURL"
value="jdbc:mysql://localhost:3306/playground?useUnicode=true&characterEncoding=UTF-8"/>
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
<property name="openjpa.ConnectionUserName" value="guest"/>
<property name="openjpa.ConnectionPassword" value="guest"/>
<!-- Classes should be enhanced at build-time for production. -->
<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
<property name="openjpa.DynamicEnhancementAgent" value="true"/>
<!-- Enable logging -->
<property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE" />
<property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" />
</properties>
</persistence-unit>
</persistence>
Have the same error. After some debugging I found out that the lines which print it out are from the patch for: OPENJPA-2233. It also changes condition to add pcNewObjectIdInstance, but it doesn't affect MappedSuperclass objects.
I think we shouldn't bother. I'll create an issue on apache JIRA.
Having the same problem with OpenJpa 2.2.2.
Its something related to the persistence.xml - when I enhance my entities with a persistence.xml configured for HSqlDb then everything works. When I use a persistence.xml configured for MySql Cluster it bombs out with that error. So it seems something in the persistence.xml triggers another path in the code during enhancement that just doesn't work.
Will come back and comment if I figure out something useful.
My persistence.xml with both configurations
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="testdb" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>code.TestDataBean</class>
<class>code.shared.DataBean</class>
<class>code.shared.AbstractDataBean</class>
<properties>
<!-- HSqlDb -->
<!--
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />
<property name="openjpa.ConnectionURL" value="jdbc:hsqldb:testdb" />
<property name="openjpa.ConnectionDriverName" value="org.hsqldb.jdbcDriver" />
<property name="openjpa.ConnectionUserName" value="sa" />
<property name="openjpa.ConnectionPassword" value="" />
<property name="openjpa.Log" value="DefaultLevel=TRACE" />
-->
<!-- MySql Cluster port 5000 -->
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:5000/clusterdb" />
<property name="openjpa.ConnectionUserName" value="root" />
<property name="openjpa.ConnectionPassword" value="" />
<property name="openjpa.BrokerFactory" value="ndb" />
<property name="openjpa.jdbc.DBDictionary" value="TableType=ndb"/>
<property name="openjpa.ndb.connectString" value="localhost:1186" />
<property name="openjpa.ndb.database" value="clusterdb" />
<property name="openjpa.Log" value="DefaultLevel=TRACE" />
</properties>
</persistence-unit>
</persistence>
My development environment (IBM RAD 8 + WAS 8) is complaining that my project does not have a persistence.xml file. Still it seems that I can build and run my project. Is that file required and if a add one such file to make my project pass validation, what should be in that file?
The project is a web project that uses session beans and entity beans from other projects and this persistence.xml error is the only error in the project so I'd be glad to get rid of it.
Thanks for any help
Update
I searched my files for persistence.xml and it showed up in src/ and bin/ of the EJB project while the web project with servlets and jsp does not have a persistence.xml, according to my colleague the web project is using the persistence.xml from the EJB project i.e:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="PandoraArendeWeb" transaction-type="JTA">
<jta-data-source>jdbc/Mainframe_TEST_ADBUTV2</jta-data-source>
<class>se.prv.pandora.arendeprocess.entity.PRVNummer</class>
<class>se.prv.pandora.arendeprocess.entity.Ansokan</class>
<class>se.prv.pandora.arendeprocess.entity.NatAnsokan</class>
<class>se.prv.pandora.arendeprocess.entity.PctAnsokan</class>
<class>se.prv.pandora.arendeprocess.entity.ArendePerson</class>
<class>se.prv.pandora.arendeprocess.entity.Nyregistrering</class>
<class>se.prv.pandora.arendeprocess.entity.Anstalld</class>
<class>se.prv.pandora.arendeprocess.entity.Handlaggare</class>
<class>se.prv.pandora.arendeprocess.entity.OrgElement</class>
<class>se.prv.pandora.arendeprocess.entity.FysiskHandlaggare</class>
<class>se.prv.pandora.arendeprocess.entity.AnsvarigHandlaggare</class>
<class>se.prv.pandora.arendeprocess.entity.AnsvarigFysiskHandlaggare</class>
<class>se.prv.pandora.arendeprocess.entity.TeknikOmrade</class>
<class>se.prv.pandora.arendeprocess.entity.Person</class>
<class>se.prv.pandora.arendeprocess.entity.PRVNummerPerson</class>
<class>se.prv.pandora.arendeprocess.entity.Notering</class>
<class>se.prv.pandora.arendeprocess.entity.Lock</class>
<class>se.prv.pandora.arendeprocess.entity.LandKod</class>
<class>se.prv.pandora.arendeprocess.entity.ArbetsMomentLog</class>
<class>se.prv.pandora.arendeprocess.entity.SystemTypDel</class>
<class>se.prv.pandora.arendeprocess.entity.ArbetsMoment</class>
<class>se.prv.pandora.arendeprocess.entity.UnderStatus</class>
<class>se.prv.pandora.arendeprocess.entity.PatPers</class>
<class>se.prv.pandora.arendeprocess.entity.PrvLandP</class>
<class>se.prv.pandora.arendeprocess.entity.PkaPerln</class>
<class>se.prv.pandora.arendeprocess.entity.PctnPerl</class>
<class>se.prv.pandora.arendeprocess.entity.PersonToPatPersKoppl</class>
<class>se.prv.pandora.arendeprocess.entity.PRVNummerPersonKoppl</class>
<class>se.prv.pandora.arendeprocess.entity.Region</class>
<class>se.prv.pandora.arendeprocess.entity.Historik</class>
<class>se.prv.pandora.arendeprocess.entity.Egenskap</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
<!-- <persistence-unit name="PandoraArendeWeb_MSSQL" transaction-type="JTA">
<jta-data-source>jdbc/MSSQL_TEST_XA</jta-data-source>
<class>se.prv.pandora.arendeprocess.entity.PersonSearch</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
-->
</persistence>
persistence.xml files usually contain details related to your database, such as connection strings and their respective user names and passwords including other ORM related information. These details can be placed in other locations so you need not explicitly have one, although having such a file usually makes all persistence related information available in one place which makes looking up certain settings and configurations easier.
This is a sample persistence.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="<PERSISTENCE UNIT NAME>">
<properties>
<!--
<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
-->
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="<PASSWORD>"/>
<property name="hibernate.connection.url" value="jdbc:mysql://<HOST IP ADDRESS>/<DB NAME>"/>
<property name="hibernate.connection.username" value="<USERNAME>"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.c3p0.min_size" value="5"/>
<property name="hibernate.c3p0.max_size" value="20"/>
<property name="hibernate.c3p0.timeout" value="300"/>
<property name="hibernate.c3p0.max_statements" value="50"/>
<property name="hibernate.c3p0.idle_test_period" value="3000"/>
</properties>
</persistence-unit>
</persistence>
The above content was taken from here.
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="AINS" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.tridenthyundai.ains.domainobject.AccessoriesDO</class>
<class>com.tridenthyundai.ains.domainobject.BranchDO</class>
<class>com.tridenthyundai.ains.domainobject.ContactDO</class>
<class>com.tridenthyundai.ains.domainobject.CustomerDO</class>
<class>com.tridenthyundai.ains.domainobject.FinanceDO</class>
<class>com.tridenthyundai.ains.domainobject.InsuranceDO</class>
<class>com.tridenthyundai.ains.domainobject.MessageDO</class>
<class>com.tridenthyundai.ains.domainobject.NotificationDO</class>
<class>com.tridenthyundai.ains.domainobject.ProductDO</class>
<class>com.tridenthyundai.ains.domainobject.ProductPriceDO</class>
<class>com.tridenthyundai.ains.domainobject.ProductSpecDO</class>
<class>com.tridenthyundai.ains.domainobject.ProductVariantDO</class>
<class>com.tridenthyundai.ains.domainobject.PurchaseDO</class>
<class>com.tridenthyundai.ains.domainobject.ServiceCentreDO</class>
<class>com.tridenthyundai.ains.domainobject.ServiceDO</class>
<class>com.tridenthyundai.ains.domainobject.ServiceTypeDO</class>
<class>com.tridenthyundai.ains.domainobject.UserDO</class>
<class>com.tridenthyundai.ains.domainobject.VisitorDO</class>
<!-- shouldn't be valid for java SE per specification, but it works for EclipseLink ... -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<!-- For Local Testing -->
<!-- <properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://saptalabs:3306/tridenthyundai" />
<property name="javax.persistence.jdbc.user" value="adminuser" />
<property name="javax.persistence.jdbc.password" value="adminuser" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="eclipselink.cache.shared.default" value="false"/>
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="SEVERE" />
</properties> -->
<!-- For Production -->
</persistence-unit>
</persistence>
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="saptalabs" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.sapta.hr.domainobject.UserDO</class>
<class>com.sapta.hr.domainobject.EmployeeDO</class>
<class>com.sapta.hr.domainobject.AddressDO</class>
<class>com.sapta.hr.domainobject.EmpDetailDO</class>
<class>com.sapta.hr.domainobject.EmpAccDetailDO</class>
<class>com.sapta.hr.domainobject.ProjectDO</class>
<class>com.sapta.hr.domainobject.CustomerDO</class>
<class>com.sapta.hr.domainobject.EmpAssignmentDO</class>
<class>com.sapta.hr.domainobject.EmpAboutDO</class>
<class>com.sapta.hr.domainobject.EmpAchievementsDO</class>
<class>com.sapta.hr.domainobject.EmpEmploymentHistoryDO</class>
<class>com.sapta.hr.domainobject.EmpSportsDO</class>
<class>com.sapta.hr.domainobject.EmpCulturalsDO</class>
<class>com.sapta.hr.domainobject.EmpEducationDO</class>
<class>com.sapta.hr.domainobject.EmpLanguageKnownDO</class>
<class>com.sapta.hr.domainobject.EmpReferencesDO</class>
<class>com.sapta.hr.domainobject.EmpSkillSetDO</class>
<class>com.sapta.hr.domainobject.EmpFamilyBackgroundDO</class>
<class>com.sapta.hr.domainobject.AssetDO</class>
<class>com.sapta.hr.domainobject.AssetTypeDO</class>
<class>com.sapta.hr.domainobject.EmpCTCDO</class>
<class>com.sapta.hr.domainobject.ExpenseDO</class>
<class>com.sapta.hr.domainobject.ExpTypeDO</class>
<class>com.sapta.hr.domainobject.InvoiceDO</class>
<class>com.sapta.hr.domainobject.PayrollDO</class>
<class>com.sapta.hr.domainobject.ProfessionalTaxDO</class>
<class>com.sapta.hr.domainobject.TDSDO</class>
<class>com.sapta.hr.domainobject.VendorDO</class>
<class>com.sapta.hr.domainobject.BillsDO</class>
<class>com.sapta.hr.domainobject.EmpLoseOfPayDO</class>
<!-- shouldn't be valid for java SE per specification, but it works for
EclipseLink ... -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<!-- For Local Testing -->
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/hrportal" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="eclipselink.cache.shared.default" value="false" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
<property name="eclipselink.logging.level" value="SEVERE" />
</properties>
</persistence-unit>
</persistence>
I've been searching around and haven't been able to find a working fix. My persistence.xml file is located in /src/META-INF/persistence.xml, which from looking around, this is the correct location for it.
I'm using glassfish as the server, and I keep getting the following:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named pers
Here is my persistence file:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="pers" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>cs.ee.assignment2.Client</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/assignment2" />
<property name="hibernate.connection.password" value="root" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
</persistence>
Any ideas on what the problem could be would be greatly appreciated.
Hmm.. make sure you are using PeristenceUnit not context in your entity class: see http://openejb.apache.org/jpa-concepts.html
Switch to "transaction" just to see if it fails too.
Also sometimes the old classes are not unloaded from the server properly if you are doing redeployment, you may have to shut it down and restart after redeploy.
I'm having some problem with EclipseLink. I'm using GlassFish v3.1 and I'm trying to use EclipseLink for my persistence layer. I followed all tutorials available on the Eclipse wiki without luck. My persistence.xml file cannot be parsed and I receive this error while trying to create the EntityManagerFactory:
org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while processing persistence.xml from URL: bundle://307.1:1/
Here is my persistence.xml located in /WEB-INF/classes/META-INF/:
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="generic">
<class>com.generic.domain.Service</class>
<properties>
<!-- Embedded MySQL Login -->
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306"/>
<!-- TODO: replace with connection pool -->
<property name="javax.persistence.jdbc.userid" value="root"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="eclipselink.target-database" value="MySQL"/>
<property name="eclipselink.jdbc.read-connections.min" value="1"/>
<property name="eclipselink.jdbc.write-connections.min" value="1"/>
<property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
<!-- Logging Settings -->
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.thread" value="false" />
<property name="eclipselink.logging.session" value="false" />
<property name="eclipselink.logging.exceptions" value="true" />
<property name="eclipselink.logging.timestamp" value="false"/>
</properties>
</persistence-unit>
</persistence>
I added this line to my MANIFEST.MF:
JPA-PersistenceUnits: generic
I can now confirm that it's a bug in EclipseLink. The work around to your problem is to either get hold of EntityManagerFactory using JNDI lookup or #PersistenceUnit instead of doing Persistence.createEntityManagerFactory().
1) It looks like you are trying to use OSGi/JPA from your WAB. Correct?
2) Can you tell if you have installed any new eclipselink bundles in your system? If so, what are they?
3) Can you provide stack trace?