-->
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.  [ 6 posts ] 
Author Message
 Post subject: Joined Subclass question
PostPosted: Wed Dec 15, 2004 10:58 am 
Regular
Regular

Joined: Fri Feb 13, 2004 10:02 pm
Posts: 90
Hibernate version:
Hibernate 2 is preferred as we're using the Spring Framework, but I can use 3 if neccessary


Question

I have used Hibernate a fair amount, but I have come to a problem and I can't seem to find the solution. I need to take an existing set of objects and an existing legacy database and use Hibernate for my data access. Below is a description of my problem.

-> = extends

Document -> Object
Application -> Document

I have 2 database tables
Document and Application

This would normally be solved with a joined subclass. However, I also have a primary key in the Application table that needs to be persited as well as a foreign key to the Document table. This is critical since Legacy applicaitons still require the Appliaction.ApplicationID field. The primary keys should be identities, can anyone show me an example of how to accomplish this without using lifecycles? I would like to keep my POJO's as decoupled from the Data Access layer as possible since this logic will ultimately be moved to a remote stateless bean.

Thanks,
Todd


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 3:24 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what about trigger or better: add logic in the setter (when setting the fk, also set the pk).
how should be the pk generated? which values?
please give more info

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 6:29 pm 
Regular
Regular

Joined: Fri Feb 13, 2004 10:02 pm
Posts: 90
Hey Anthony,
Thanks for the reply. Adding a database trigger is out of the question, we are not allowed to modify the existing database in any way. As far as a setter on the primary key when getting the foreign key, I could do that, but again I would be coupling the DAO logic to the business logic. I would have to get the next identity if the Long primary key were null. Is there some sort of existing mapping that could be used in my situation? There is the "key" attribute for a joined-subclass, but it just references the primary key of the parent class. Is there some way to also insert the standard "id" tag within a joined sublcass? This would keep the business POJO's and the DAO layers completely seperated, and keep generating identities significantly easier.

Thanks,
Todd


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 16, 2004 4:09 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
argh, there is an excellent feature in hibernate 3: lazy formula.
If you don't have a short deadline and can wait for H3 release candidate , you should be able to map a "select nextval" lazy formula. With that, MVC pattern won't be broken.

If you can't wait, this is the role of your controller to ask your DAO layer the next val (this dao method can be in pure jdbc) and pass it to your pojo when needed.

This is not so hard, just imagine this primary key is a business field that needs the controller help to be filled.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Thu Dec 16, 2004 10:27 am 
Regular
Regular

Joined: Fri Feb 13, 2004 10:02 pm
Posts: 90
Thanks for the help Anthony, I can wait a little while for Hibernate 3. I'm trying to champion the use of Hibernate instead of the current architecture, which are DAO’s with SQL and cascading/foreign key updates within the business objects (YUK!). I really want to move to Hibernate for the ease of business logic development, as well as optimal SQL generation since some of the SQL currently in place is somewhat slow. I have one final question. Will we also be able to use Hibernate to connect to a DB2 mainframe database on VM? It supports a type 4 JDBC driver, but all of the meta-data is not available for the databases, as well as outer joins are unavailable. I know I can disable outer joins by setting hibernate.max_fetch_depth to 0, but will Hibernate have problems during the Session initialization due to the incomplete meta-data?

Thanks,
Todd


Top
 Profile  
 
 Post subject: Hibernate 3 questions/examples
PostPosted: Fri Mar 04, 2005 12:02 pm 
Regular
Regular

Joined: Fri Feb 13, 2004 10:02 pm
Posts: 90
Hibernate version:
3.0rc1


Hi Anthony,
I'm back again, and I need some more help. We are beginning development with Hibernate 3, and I will wait for Spring to release 1.2 with Hibernate 3 support. I have the following object scenario

-> = Excends

#> = Foregin Key to primary key.


Object setup

Application -> Document

Application has many ApplicationEntityRoles


Database setup

Application #> Document (joined sublcass by document id, that part is easy)

ApplicationEntityRole #> Application.

NOTE: Application has is own primary key, and this is required by legacy apps!

You mentioned in your earlier posts that a column and a formula could be used. I've reviewed the documentation, and it is not clear to me how to utilize this. Is there an example somewhere? Also, from my understanding of Hibernate, if I map a Set of AppliationEntityRoles into the Appliation mapping, it will be default use the primary key in Document correct?

Take the following mapping within the application joined sublcass mapping



<set name="appEntityRoles" table="APPENTITYROLE" inverse="true" lazy="false" cascade="all">
<key column="ApplicationID"/>
<one-to-many class="com.llic.data.ApplicationEntityRole"/>
</set>



When the sql is generated, won't this join APPENTITYROLE.ApplicationID = Document.DocumentID? Is there any way around this? I have used hibernate quite a bit, but it has always been on a new project. I'm not sure what I should do here to resolve the issue. If this is possible, what is the best way to do this?

Thanks,
Todd


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