-->
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.  [ 3 posts ] 
Author Message
 Post subject: mutiple schemas in hibernate
PostPosted: Wed Feb 25, 2004 5:46 pm 
Newbie

Joined: Mon Nov 17, 2003 10:53 am
Posts: 15
hi,

i would like to create a modell that reads and writes to
multiple schemas in mysql. the clou on it is
that i have to classes Foo and Bar that reside in
different schemas (in mysql terms databases);
where Foo has a reference on Bar

first the java code
Code:
public class Foo
{   ...
    public String getId(){return id_;}
    public Foo setId(String _id)
    {id_ = _id;return this;}

    public Bar getBar(){return bar_;}
    public Foo setBar(Bar _value)
    {bar_=_value;return this;}     

    public String getName(){return name_;}
    public Foo setName(String _value)
    {name_ = _value;return this;}}

public class Bar
{   ...
    public String getId(){return id_;}
    public Bar setId(String _id)
    {id_ = _id;return this;}

    public String getName(){return name_;}
    public Bar setName(String _value)
    {name_ = _value;return this;}}
}


now here the database
Code:
create database A;
use A;
create table FOO
    (   ID CHAR(32) NOT NULL PRIMARY KEY,
        NAME VARCHAR(50) NULL ,
        BAR_ID CHAR(32) NOT NULL,
    ) TYPE = INNODB;


create database B;
use B;
create table BAR
    (   ID CHAR(32) NOT NULL PRIMARY KEY,
        NAME VARCHAR(50) NULL ,
    ) TYPE = INNODB;


now the mappings
Code:
<hibernate-mapping>
    <class name="org.pragmatico.Foo"
        table="FOO" schema="A"
        dynamic-update="false" dynamic-insert="false">

        <id name="id" column="id" type="java.lang.String">
            <generator class="uuid.hex"/>
        </id>

        <many-to-one name="bar"
            class="org.pragmatico.Bar" cascade="none"
            outer-join="auto" update="true"
            insert="true" column="MERCHANT_ID"/>

        <property name="name"
            type="java.lang.String" update="true"
            insert="true" column="name"/>
    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class
        name="org.pragmatico.Bar" table="BAR"
        schema="B" dynamic-update="false"
        dynamic-insert="false">

        <id name="id" column="id" type="java.lang.String">
            <generator class="uuid.hex"/>
        </id>

        <property name="name"
            type="java.lang.String" update="true"
            insert="true" column="name"/>
    </class>
</hibernate-mapping>


and finally the hibernatexml.cfg
Code:
<hibernate-configuration>
    <session-factory>
        <property
           name="hibernate.connection.driver_class">
              com.mysql.jdbc.Driver</property>
        <property
           name="hibernate.connection.url">
              jdbc:mysql://localhost/</property>
        <property
           name="hibernate.dialect">
              net.sf.hibernate.dialect.MySQLDialect</property>

        <mapping
          resource="org/pragmatico/Foo.hbm.xml"/>
        <mapping
          resource="org/pragmatico/Bar.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


now for the love of god i cant figure out how to get that
running. i tried to put the name of the database to the
connection.url i added and removed the schema-attr
on the mappings i did this i did that. i simply dont know
what to do. maybe its not possible.

what i want to do boils down to this
Code:
Foo foo = new Foo();
foo.setName("FOO 01");
Bar bar = new Bar();
bar.setName("BAR 01");
foo.setBar(bar);

Configuration conf = new Configuration();
conf.configure();
SessionFactory sessionFactory =
                      conf.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();

session.save(foo);

transaction.commit();
session.close();


any ideas.

thank you

ciao robertj


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 6:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
What is the problem if you put that schema attribute there? If you get the "uses an underscore" problem, search the forum it has allready been discussed multiple times. If not, please describe your problem better than "does not work", for example check and probably post the generated SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 4:43 am 
Newbie

Joined: Mon Nov 17, 2003 10:53 am
Posts: 15
gloeglm wrote:
What is the problem if you put that schema attribute there? If you get the "uses an underscore" problem, search the forum it has allready been discussed multiple times. If not, please describe your problem better than "does not work", for example check and probably post the generated SQL.


mea culpa, mea maxima culpa.

i am very ashamed that i did not know to search for
"underscore mysql" which indeed has been been discussed
multiple times (2x) and which is so obvious.
what an incredible oversight of my self.

i wont bother you with my unworthy questions anymore.

thank you

robertj


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.