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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate using 2 datasources.
PostPosted: Tue Apr 03, 2007 8:54 am 
Newbie

Joined: Tue Mar 20, 2007 11:48 am
Posts: 11
Hi to all,

I'm new to Hibernate and got stuck with a quite advanced problem. The application needs to get it's data from 2 datasources. One datasource that hold data of the users (users), and one that holds data specific for the application (items). Now the problem is that there is an object that holds an instance of both:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   
<class name="libraryImpl.HireDetailsImpl" table="hiredetails">
   <composite-id>
      <key-many-to-one name="item" class="libraryImpl.ItemImpl" column="itemId" lazy="false" />
      <key-many-to-one name="user" class="corporateImpl.UserImpl" column="userId" lazy="false" />   
   </composite-id>
   <property name="startDate" type="date" column="startDate" />
   <property name="endDate" type="date" column="endDate" />
</class>
   
</hibernate-mapping>


The problem is that I can't place the Users-mapping in the mapping-resources of the datasource that provides the Items and vice versa because they don't know of each other.
Any idea how this can be solved?
Thanks in advance..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 9:02 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
implementing your own load, update, delete, etc commands on some dummy object. If you have complex sql queries to perform on this, you just have to break them up. I don't know the scope of your project or if it's the ideal way to do this, but I think it has some potential.


app = item. just used wrong word from your post

Code:
dataSource1 -> user
dataSource2 -> app

DummyObject {
private User user;
private App app;
}

//here's your session which overrides any methods you wish
customSession extends session {

public Object load(PrimaryKey PK) {
new DummyObject();
User user = dataSource1.session.load(User user, PK);
App app = dataSource2.session.load(App app, PK);
DummyObject.setUser(user);
DummyObject.serApp(app);

return DUmmyObject;

}

}

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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