0

I have worked first with Ingres database and there weren't problems there. I have configured my MySQL Database with two Schemas/Catalogs in the same port, one for producers and the other for testing. In the persistence.xml file, I have the following configuration:

<persistence-unit name="my_schema">
    ... classes ...

    <properties>
        <property name="hibernate.connection.url" value="jdbc:mysql://URL:3306/my_schema"></property>
        <property name="hibernate.connection.username" value="my_user"></property>
        <property name="hibernate.connection.password" value="my_pass"></property>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"></property>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"></property>
        <property name="hibernate.connection.nombre" value="my_schema" />

    </properties>
</persistence-unit>

My Java Entity Classes have the following definition and annotations:

/**
* Constante generated by hbm2java
*/
@Entity
@Table(name = "CONSTANTE", catalog = "my_schema")
public class Constante implements java.io.Serializable {
    ....
}

When I worked in Ingres, if I wanted to change the schema/catalog, I only needed to change the property "hibernate.connection.url" in persistence.xml:

<property name="hibernate.connection.url" value="jdbc:mysql://URL:3306/my_schema_2">

In MySQL, I have to change the "catalog" annotation in every single class. Is there an easier or more practical way to do this? In fact, in MySQL, I can write whatever I want in the url schema part and the program continues working.

Darshan Lila
  • 5,772
  • 2
  • 24
  • 34
user2508640
  • 11
  • 1
  • 4

1 Answers1

0

As your entity class has been generated from the schema:

/**
 * Constante generated by hbm2java
 */

you can simply remove the catalog entry in the Table annotation:

@Entity
@Table(name = "CONSTANTE")
public class Constante implements java.io.Serializable {

Then, like you have experienced before, if you need to change schema, simply change the value of hibernate.connection.url.

JamesB
  • 7,774
  • 2
  • 22
  • 21
  • It works perfect but ... is it possible to generate classes without the catalog annotation instead of removing it manually in every class? – user2508640 Jul 29 '14 at 12:19
  • resolved with this solution, thank you! http://stackoverflow.com/questions/1218028/running-hibernate-tool-annotation-generation-without-the-catalog-attribute – user2508640 Jul 29 '14 at 12:48