how to make ha-jdbc datasource work - java

i have a ha-jdbc xml where i have this configuration:
<ha-jdbc>
<sync id="diff" class="net.sf.hajdbc.sync.DifferentialSynchronizationStrategy">
<property name="fetchSize">1000</property>
<property name="maxBatchSize">100</property>
</sync>
<sync id="full" class="net.sf.hajdbc.sync.FullSynchronizationStrategy">
<property name="fetchSize">1000</property>
<property name="maxBatchSize">100</property>
</sync>
<cluster balancer="load"
dialect="net.sf.hajdbc.dialect.MySQLDialect"
default-sync="full"
transaction-mode="parallel"
auto-activate-schedule="0 * * ? * *"
failure-detect-schedule="0 * * ? * *"
meta-data-cache="none">
<database id="database1">
<driver>****</driver>
<url>****</url>
<user>****</user>
<password>****</password>
</database>
<database id="database2">
<driver>****</driver>
<url>****</url>
<user>****</user>
<password>****</password>
</database>
</cluster>
</ha-jdbc>
i am accessing ha-jdbc using jpa config:
<?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="app_data" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.driver_class" value="net.sf.hajdbc.sql.Driver" />
<!--property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/-->
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="hibernate.connection.url" value="jdbc:ha-jdbc:cluster1" />
<property name="hibernate.connection.username" value="****" />
<property name="hibernate.connection.password" value="****" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<!--property name="hibernate.hbm2ddl.auto" value="update" /-->
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="20" />
<property name="hibernate.c3p0.timeout" value="1800" />
<property name="hibernate.c3p0.max_statements" value="50" />
<property name="hibernate.c3p0.idle_test_period" value="3000" />
</properties>
</persistence-unit>
when i run maven i get the following error:
org.jibx.runtime.JiBXException: Expected "cluster" end tag, found "datasource" start tag (line 19, col 11)
could anyone explain what can be the solution?

Related

configure c3p0 with eclipselink

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>

No Persistence provider for EntityManager in prod more

I've been making an app using Play Framework 2.5 and I had no problems while running it in dev mode with run command, but once I try to switch to prod mode I am having this exception:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named defaultPersistenceUnit
my persistence.xml is in conf/META-INF/ folder
<persistence 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"
version="2.1">
<persistence-unit name="defaultPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<class>models.entities.Artifact</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<property name="current_session_context_class" value="thread" />
</properties>
</persistence-unit>
<persistence-unit name="testPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<class>models.entities.Artifact</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
<property name="javax.persistence.jdbc.user" value="" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="show_sql" value="false" />
<property name="hibernate.temp.use_jdbc_metadata_defaults"
value="false" />
</properties>
</persistence-unit>
Please give me at least some clues to where the problem might be

Spring mvc multiple entities database persistance

I'm having troubles with "working with multiple databases" in Spring MVC - hibernate JPA
I have two databases called user_db and portal_db. I need to work with them in different jpa units.
here is my persistance.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="user_unit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>Package.Entity1</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost/user_db" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.username" value="postgres" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL82Dialect" />
<!--<property name="hibernate.hbm2ddl.auto" value="create-drop" />-->
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
<persistence-unit name="portal_unit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>Package.Entity2</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost/portal_db" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding" value="UTF-8" />
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.username" value="postgres" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL82Dialect" />
<!--<property name="hibernate.hbm2ddl.auto" value="create-drop"/>-->
<property name="hibernate.hbm2ddl.auto" value="validate"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
Problem is When I use create-drop and run my project, it creates both of my entites in both databases. Like table that should be only created by Package.Entity1 in user_unit, is also created in portal_unit.
And when I select,insert,update my entites, I set persistance unit in each of my individual DAO's.
for example, in Entity Dao's implementation I have:
EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit);
where persistenceUnit could be user_unit or portal_unit depending on implementation.
What changes should I make so it wont create same table in both databases?
Add <exclude-unlisted-classes>true</exclude-unlisted-classes> in both of yours persistence units OR use JPA 2.x
Add <exclude-unlisted-classes>true</exclude-unlisted-classes> in both your persistence units.
Please follow post below for detailed explanation:
Multiple persistance unit in persistence.xml creating tables in one another

Changing database in eclipse/hibernate project

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)

"Unknown database 'mydb' " error with jpa

i'm trying to connect to mysql server but get this error. when mydb is the only name in the system. please tell me where i'm wrong...
my persistence xml is as folow:
<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="MyPersistenceUnit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/mydb" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="tft" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="true" />
</properties>
</persistence-unit>
</persistence>
1.You have to check your mysql jdbc driver
2.You have to check mysql server state and validation of username & password.

Categories

Resources