Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate and multiple databases
    text
    copied!<p>I'm trying to solve pretty easy problem. I want to establish connection to 2 totally different databases ( but both mysql ). Now I tried to solve this by creating multiple config files and then creating multiple sessions. Everything works until I reached relations.</p> <p>I have 2 tables in 2 databases:</p> <p>db1 - News</p> <p>db2 - News_Authors</p> <p>I added News to db1 config and News_Authors to db2 config. When I try to build simple one-to-one relation error, I receive:</p> <pre><code>An association from the table songs refers to an unmapped class: db1.News_Authors </code></pre> <p><strong>News.hbm.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt; &lt;class name="project.News, project" table="news" lazy="false"&gt; &lt;id name="id" column="id" type="integer" length="11"&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;property name="title" type="String" length="255" /&gt; &lt;property name="authorid" type="integer" length="5" /&gt; &lt;one-to-one name="NewsAuthor" cascade="all-delete-orphan" lazy="proxy" column="authorid" unique="true" /&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p><strong>News_Authors.hbm.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt; &lt;class name="project.News_Authors, project" table="news_authors" lazy="false"&gt; &lt;id name="id" column="id" type="integer" length="11"&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;property name="name" type="String" length="255" /&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p><strong>config</strong> I added this to enable mappings. Now If I set both in one config files, everything works...</p> <pre><code>&lt;mapping resource="project.News.hbm.xml" assembly="project" /&gt; </code></pre> <p>So how could I during creating of session also "notify" nhibernate that I have multiple sessions? Or should I pick totally another approach?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload