I am using EclipseLink in my project. Due to some connection pool issue, I have to use c3p0 with EclipseLink. Is it possible to use both c3p0 and EclipseLink configuration both combined as follows,
<persistence-unit name="samplePU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.sessions-xml" value="META-INF/sessions.xml"/>
<property name="eclipselink.session-name" value="xxx"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.max_size" value="100" />
<property name="hibernate.c3p0.min_size" value="0" />
<property name="hibernate.c3p0.acquire_increment" value="1" />
<property name="hibernate.c3p0.idle_test_period" value="300" />
<property name="hibernate.c3p0.max_statements" value="0" />
<property name="hibernate.c3p0.timeout" value="100" />
<!-- properties to fine tune logging -->
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.logging.timestamp" value="true"/>
<property name="eclipselink.logging.thread" value="true"/>
<property name="eclipselink.logging.session" value="true"/>
</properties>
</persistence-unit>
Related
I have 10 entities in package:
com.paka.maka.raka
I have 5 entities in package
com.paka
I only want to scan 10 entities in first package name.
Is it mandatory to name whole classes or is there way to give package name only to scan in Persistance.xml
<persistence-unit name="IntegratorMasterdataPU" transaction-type="RESOURCE_LOCAL" >
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:#dat-esb-orat:1521/rator_test" />
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.connection.username" value="DATA" />
<property name="hibernate.connection.password" value="264rcxx" />
<!--QA <property name="hibernate.connection.password" value="emifuqqgqn5" /> -->
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<!-- <property name="hibernate.hbm2ddl.auto" value="create" /> -->
</properties>
</persistence-unit>
I'm not pretty sure it will work, but you can use:
<property name="packagesToScan" value="com.paka.maka.raka"/>
In your entityManagerFactory bean declaration
Check this post
I use hibernate and i want to basic crud but i didn't configure persistence.xml and applicationContext.xml configuration file. I want to use EntityManager instead of Session.
This is my applicationContext.xml
<context:annotation-config />
<context:component-scan base-package="com.toyotaproject" />
<tx:annotation-driven />
<bean class = "org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3307/toyotadb" />
<property name="username" value="root" />
<property name="password" value="12345" />
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<context:component-scan base-package="com.toyotaproject.domain" />
<property name="persistenceXmlLocation" value="SpringJPA_PU"></property>
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaAdapter" />
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="jpaAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
</bean>
</beans>
this is my 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"
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="SpringJPA_PU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.toyotaproject.domain.Customer </class>
<class>com.toyotaproject.domain.Trip </class>
<class>com.toyotaproject.domain.Reservation </class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3307/toyotadb" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="12345" />
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>
<!-- If you are using Hibernate's proprietary API, you'll need the hibernate.cfg.xml.
If you are using JPA i.e. Hibernate EntityManager, you'll need the persistence.xml. -->
<!-- SQL -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name ="hibernate.format_sql" value="true"/>
<property name ="hibernate.show_sql" value="true"/>
<!-- C3P0 -->
<property name="hibernate.c3p0.acquire_increment" value="2"/>
<property name="hibernate.c3p0.max_size" value="20"/>
<property name="hibernate.c3p0.min_size" value="5"/>
<property name="hibernate.c3p0.timeout" value="180"/>
<property name="hibernate.c3p0.idle_test_period" value="100"/>
<property name="hbm2ddl.auto" value="update"/>
<!-- property name="eclipselink.logging.level" value="OFF" /-->
</properties>
</persistence-unit>
</persistence>
Where am i doing wrong ?
I have two projects:
common and hrm
project common is a parent project(packaged as Jar) and hrm is a dependent project(packaged as war)
Dependency is specified through maven
Maven dependency is specified as:
<dependency>
<groupId>com.talentera</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
My persistence XML in hrm project:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<persistence-unit name="talentera" transaction-type="RESOURCE_LOCAL">
<description>example of enabling the second level cache.</description>
<jta-data-source>java:jboss/datasources/TalenteraDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<jar-file>../../lib/common-0.0.1-SNAPSHOT.jar</jar-file>
<properties>
<property name="hibernate.cache.use_second_level_cache" value="false" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.bytecode.use_reflection_optimizer" value="false" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.use_outer_join" value="false" />
<property name="hibernate.cache.use_structured_entries" value="true" />
<property name="hibernate.generate_statistics" value="true" />
<property name="hibernate.id.new_generator_mappings" value="false" />
<property name="hibernate.default_batch_fetch_size" value="500" />
<property name="hibernate.max_fetch_depth" value="5" />
<property name="hibernate.jdbc.batch_size" value="1000" />
<property name="jboss.as.jpa.managed" value="false" />
<property name="hibernate.archive.autodetection" value="class, hbm"/>
</properties>
</persistence-unit>
</persistence>
Spring configuration:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="appDataSource" />
<property name="persistenceUnitName" value="talentera" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
</bean>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
</bean>
<bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="appDataSource" />
</bean>
Please help me to make the entities available in common to be auto recognized in hrm project by spring-jpa
common is packaged as Jar and hrm is packaged as war.
Please let me know if I need to provide any more information here.
I had your same problem with a composite unit, I solved in this way:
you have to change
<jar-file>../../lib/common-0.0.1-SNAPSHOT.jar</jar-file>
with
<jar-file>WEB-INF/lib/common-0.0.1-SNAPSHOT.jar</jar-file>
ii should work
My peristance file is:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL">
<!-- provider -->
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>sau.se.migration.model.TGridStation</class>
<class>sau.se.domain.model.Graph</class>
<class>sau.se.domain.model.Role</class>
<class>sau.se.domain.model.StationPrincipale</class>
<class>sau.se.domain.model.StationSecondaire</class>
<class>sau.se.domain.model.User</class>
<class>sau.se.domain.model.Incident</class>
<class>sau.se.domain.model.Listes</class>
<class>sau.se.domain.model.Vip</class>
<class>sau.se.domain.model.Feeder</class>
<properties>
<!-- Classes persistantes -->
<!--<property name="hibernate.archive.autodetection" value="class, hbm"
/> -->
<!-- logs SQL -->
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<property name="use_sql_comments" value="true" />
<!-- connexion JDBC -->
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost/semap?zeroDateTimeBehavior=convertToNull" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding"
value="UTF-8" />
<property name="hibernate.connection.charSet" value="UTF-8" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="123456789" />
<!-- Dialecte -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
</persistence>
And I am quiet sure that it is the only configuration file in my project because I tried to put wrong password and I got the expected error on connection.
I want to change semap db name to any other but in vain.
Is there any other configuration that I don't know?
UPDATE
The real problem is that my application is still working with semap db (the old one)
I'm developing an application with eclipseLink and Spring. For now I'm using h2 like database. My trouble is that eclipseLink is not able to create tables.
This is my configuration.
Persistence.xml:
<persistence>
<persistence-unit name="myUnit">
//some classes definition
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:file:C:\Users\user\Desktop\myFolder\test.db" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.composite-unit.member" value="true"/>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.H2Platform"/>
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.create-ddl-jdbc-file-name" value="create.sql"/>
</properties>
</persistence-unit>
</persistence>
spring-context.xml
<beans>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="emf">
<property name="persistenceUnitName" value="myUnit" />
</bean>
<bean id="eclipseLinkJpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
</bean>
<tx:annotation-driven />
<bean id="emf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:jpaVendorAdapter-ref="eclipseLinkJpaVendorAdapter"
p:persistenceUnitName="myUnit">
<property name="jpaPropertyMap">
<map>
<entry key="eclipselink.cache.shared.default" value="false" />
<entry key="eclipselink.weaving" value="false" />
</map>
</property>
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
</beans>
Moreover i find the file create.sql empty!!!
Where am I doing wrong?