-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Create table in only one of x Databases
PostPosted: Tue Feb 03, 2009 11:16 am 
Newbie

Joined: Tue Feb 03, 2009 10:49 am
Posts: 10
Hi

Hibernate version: 3.2.4.sp1
Hibernate Annotations: 3.2.1.GA
Mapping documents:
Name and version of the database you are using: MySQL 5

i configured 2 databases which i want access from my SEAM 2.0.2 SP1 application.
Both DBs are different, i use the first one to store my objects and the other one just to read data.

i can access both DBs without any problems. My problem is that the Java Entities (and thus the DB tables) i've created are automatically created in BOTH DBs. I don't want that.

I tried to annotate the entitys like this:
Code:
@Entity
@Table(name="tableA",schema = "schemaX")
.... JavaSource .....

this works but gives me error messages like:
Quote:
15:00:47,265 INFO [DatabaseMetadata] table not found: tableA
15:00:47,281 ERROR [SchemaUpdate] Unsuccessful: create table schemaX.tableA (...) type=InnoDB
15:00:47,281 ERROR [SchemaUpdate] Table 'tableA' already exists


Is there a way to tell hibernate to bind a table only to a specific database? I' quite sure there is but i couldn't find it.

Thanks for your guidance,
BR hugo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 7:12 pm 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
What does your configuration look like?

If Hibernate isn't being used for the second database, then don't let Hibernate know that it even exists.

--
Stephen Souness


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 10:06 am 
Newbie

Joined: Tue Feb 03, 2009 10:49 am
Posts: 10
i need hibernate for both DBs (it just came to my mind that i will have to write to the 2nd DB too).
datasources:
Code:
<datasources>
   
   <local-tx-datasource>
      <jndi-name>DB</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/db</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>...</user-name>
      <password>...</password>
   </local-tx-datasource>
   
      <local-tx-datasource>
      <jndi-name>IsisDatasource</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/isis</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>...</user-name>
      <password>...</password>
   </local-tx-datasource>
   
</datasources>


components.xml
Code:
..
<persistence:managed-persistence-context name="DBManager"
                                     auto-create="true"
                      persistence-unit-jndi-name="java:/DBEntityManager"/>
                     
   <persistence:managed-persistence-context name="IsisManager"
               auto-create="true"
                      persistence-unit-jndi-name="java:/IsisEntityManager"/>   
..


persistence.xml
Code:
<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="DB2">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/DB</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.show_sql" value="false"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="jboss.entity.manager.jndi.name" value="java:/DBEntityManager"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/DBEntityManagerFactory"/>
      </properties>
   </persistence-unit>
   
   <persistence-unit name="Isis">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/IsisDatasource</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.show_sql" value="false"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="jboss.entity.manager.jndi.name" value="java:/IsisEntityManager"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/IsisEntityManagerFactory"/>
      </properties>
   </persistence-unit>
   
</persistence>


hibernate.cfg
Code:
<hibernate-configuration>
  <!--  <session-factory name="java:/DBDatasource">-->
   <session-factory>
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!--      <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> -->
<!--     <property name="connection.datasource">java:/DefaultDS</property> -->
   <property name="connection.datasource">java:/DB</property>
    <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
    <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
    <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
     <property name="hbm2ddl.auto">update</property>
<!-- <property name="hbm2ddl.auto">create-drop;update</property>-->
   <property name="show_sql">false</property>

... mappings for jbpm stuff ...


edit: schemaX (from post1) would be DB or Isis.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 2:33 pm 
Newbie

Joined: Wed Mar 18, 2009 2:25 pm
Posts: 1
Does anyone have a solution for this? I am having the exact same problem.
I am also using Seam and JBoss 5.0. I have two datasources one is mySql and the other is Oracle.

My messageToClient entity class table is being created in both persistent units. The other classes are from another jar so those are fine. From the xml below it should only be created in the integration unit.


Here is my persistence.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<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="orderProcessor">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/orderProcessorDatasource</jta-data-source>
      <jar-file>acquityOnDemand-ejb.jar</jar-file>
      <class>com.acquitygroup.acquityondemand.entity.OrderHeader</class>
      <class>com.acquitygroup.acquityondemand.entity.Address</class>
      <class>com.acquitygroup.acquityondemand.entity.BillingAddress</class>
      <class>com.acquitygroup.acquityondemand.entity.ShippingAddress</class>
      <class>com.acquitygroup.acquityondemand.entity.Payment</class>
      <class>com.acquitygroup.acquityondemand.entity.OrderLine</class>
      <class>com.acquitygroup.acquityondemand.entity.ShippingOption</class>
      <class>com.acquitygroup.acquityondemand.entity.ShippingPrice</class>
      <class>com.acquitygroup.acquityondemand.entity.Sku</class>
      <class>com.acquitygroup.acquityondemand.entity.Product</class>
      <class>com.acquitygroup.acquityondemand.entity.SkuPrice</class>
      <class>com.acquitygroup.acquityondemand.entity.PriceList</class>
      <class>com.acquitygroup.acquityondemand.entity.ProductCategory</class>
      <class>com.acquitygroup.acquityondemand.entity.Category</class>
      <class>com.acquitygroup.acquityondemand.entity.Catalog</class>
      <class>com.acquitygroup.acquityondemand.entity.Site</class>
      <class>com.acquitygroup.acquityondemand.entity.Client</class>
      <class>com.acquitygroup.acquityondemand.entity.CreditCard</class>
      <class>com.acquitygroup.acquityondemand.entity.User</class>
      <class>com.acquitygroup.acquityondemand.entity.UserRole</class>
     
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/orderProcessorEntityManagerFactory"/>
      </properties>
   </persistence-unit>
   
   <persistence-unit name="integration">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/integrationDataSource</jta-data-source>
      <jar-file>orderProcessor-ejb.jar</jar-file>
      <class>com.acquitygroup.orderprocessor.entity.MessageToClient</class>     
     
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9Dialect"/>
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/integrationEntityManagerFactory"/>
      </properties>
   </persistence-unit>
   
</persistence>


MessageToClient.java

Code:
package com.acquitygroup.orderprocessor.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import java.math.BigDecimal;
import java.sql.Date;

@Entity
@Table(name = "MESSAGE_TO_CLIENT")
public class MessageToClient {
   
   BigDecimal messageToClientId;
   String clientCode;
   String acquityId;
   String type;
   byte[] payload;
   BigDecimal errorCount;
   Date createTimestamp;
   Date sendTimestamp;
   String locked;
   String finished;
   Date finishTimestamp;
   
   public MessageToClient(){}
   
   public MessageToClient(BigDecimal messageToClientId, String clientCode,
         String acquityId, String type, byte[] payload, BigDecimal errorCount,
         Date createTimestamp, Date sendTimestamp, String locked,
         String finished, Date finishTimestamp) {
      this.messageToClientId = messageToClientId;
      this.clientCode = clientCode;
      this.acquityId = acquityId;
      this.type = type;
      this.payload = payload;
      this.errorCount = errorCount;
      this.createTimestamp = createTimestamp;
      this.sendTimestamp = sendTimestamp;
      this.locked = locked;
      this.finished = finished;
      this.finishTimestamp = finishTimestamp;
   }
   
   @Id
   @SequenceGenerator(name="SEQ_MESSAGE_TO_CLIENT")
   @Column(name="MESSAGE_TO_CLIENT_ID", unique = true, nullable = false)
   public BigDecimal getMessageToClientId() {
      return messageToClientId;
   }

   public void setMessageToClientId(BigDecimal messageToClientId) {
      this.messageToClientId = messageToClientId;
   }
   
   @Column(name="CLIENT_CODE")
   public String getClientCode() {
      return clientCode;
   }

   public void setClientCode(String clientCode) {
      this.clientCode = clientCode;
   }

   @Column(name="ACQUITY_ID")
   public String getAcquityId() {
      return acquityId;
   }

   public void setAcquityId(String acquityId) {
      this.acquityId = acquityId;
   }
   
   @Column(name="TYPE")
   public String getType() {
      return type;
   }

   public void setType(String type) {
      this.type = type;
   }
   
   @Column(name="PAYLOAD")
   @Lob
   public byte[] getPayload() {
      return payload;
   }

   ....
}



Top
 Profile  
 
 Post subject: Re: Create table in only one of x Databases
PostPosted: Wed Aug 05, 2009 2:40 am 
Newbie

Joined: Wed Aug 05, 2009 2:37 am
Posts: 1
I also have this.

I need 2 different databases. 1 for a portal database and 1 for an application database.

When I define a new table it is created in both databases.

Isn't there a way to tell which persistence unit a table belongs to?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.