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: Wicked database schema questions
PostPosted: Tue Aug 15, 2006 3:39 am 
Newbie

Joined: Tue Aug 15, 2006 3:22 am
Posts: 3
Location: Sweden
We have a legacy application that we're working on rewriting right now, and I thought it would be a nice idea to use NHibernate instead of writing our own persistence layer. :) So I'm evaluating things, but I keep running across these difficult questions to which I can't find much answers.

Our database is pretty wicked. Mostly because customers can add their own fields to certain tables, for adding custom information. It's also both in Swedish and English - that is, the field names can be either Swedish or English, and we use different control files to map to different databases.

Question 1: I read somewhere that the bindings can be automatically generated. I figure, in a worst case scenario, we just bind to .hbm.xml files specifically for each language version. I'm not afraid of that... should I be? :)

Question 2: The extra fields are more difficult, I think. I don't suppose there's a switch or parameter somehow that allows you to "read all additional fields into this array" or something? User code (and custom dialogs) may bind to these fields, so they need to be there. Can they be read into a different class somehow, using programmatic mapping? Is it possible to bind not to property fields but to arrays or dictionaries?

Question 3: Is it possible to read a subset of a row into a class? We may, for speed purposes, not want to read every field from a row in certain cases, but only a subset. Is there HQL to support that? Or is it possible to define a Customer class, and a CustomerSubset class with less properties, that both map to the same table?

I know I'm a newbie, but I'd be thankful for any help. The other guys, who are not using NHibernate, are running awfully fast with their own persistence layer and I'm trying to save ourselves some 500+ development hours here :)

/ Mats


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 5:30 am 
Beginner
Beginner

Joined: Wed Apr 19, 2006 9:16 am
Posts: 24
Question 3:
Yes, you can. With HQL you can specify the fields you want to be returned, in which case they are returned in arrays, but you can also do something like this
Code:
select new ReportClass(c.Name, c.DateOfBirth) from Customer c  (etc., etc.)

where "ReportClass" is a custom class with a constructor that matches the parameters in brackets. I had to use an import for the custom class to get this to work, but it works.

I don't think it is mentioned in the NHibernate docs, but it is in the Hibernate docs (with a lot more examples)
http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html

Sorry, no answers to Q1 & 2 :(

_________________
regards,
Willem van Rumpt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 5:49 am 
Newbie

Joined: Tue Aug 15, 2006 3:22 am
Posts: 3
Location: Sweden
Willem van Rumpt wrote:
select new ReportClass(c.Name, c.DateOfBirth) from Customer c (etc., etc.)
where "ReportClass" is a custom class with a constructor that matches the parameters in brackets. I had to use an import for the custom class to get this to work, but it works.


Yes, I saw something similar. It would be neater though, if you could specify a class with a limited set of properties and load it directly. But the HQL version works, of course.

But the extended fields worry me. I becoming ever less convinced that Hibernate can do what we want. :(


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 6:53 am 
Beginner
Beginner

Joined: Wed Apr 19, 2006 9:16 am
Posts: 24
matsgefvert wrote:
But the extended fields worry me. I becoming ever less convinced that Hibernate can do what we want. :(


If I understand correctly, the custom user fields are appended to the table itself? Is there any chance you can refactor this database design? It probably won't be easy, considering the dependencies in other tiers, but it might turn out to be worth your while.

I don't think NHibernate can read in "additional" fields, but perhaps some of the more experienced users here know of a way to accomplish this.

_________________
regards,
Willem van Rumpt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 7:43 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can use <dynamic-component> to map columns to a dictionary, but you have to specify column names in the mappings and you can't add or remove columns while the application is running.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 8:07 am 
Newbie

Joined: Tue Aug 15, 2006 3:22 am
Posts: 3
Location: Sweden
Thanks for the answers. We're going to look into the <dynamic-component> thingy, but I'm still not sure that Hibernate is right for us after all.

So, as for now, we're running with our own ORM layer. Wish me good luck :-P

/ Mats


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.