-->
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.  [ 7 posts ] 
Author Message
 Post subject: Question/proposal auto sql-query choose based on dialect
PostPosted: Tue Jul 27, 2004 1:51 pm 
Beginner
Beginner

Joined: Mon Mar 22, 2004 9:37 am
Posts: 22
Location: Willow Grove, PA
Is it possible to have a named native sql auto selected via the current dialet setting for the session/sessionFactory.

i.e. in programming code we can refer to just "q1". and automatically be given the correct query based on the current dialet.

<sql-query name="q1_mysql" >
...
</sql-query>

<sql-query name="q1_oracle" >
...
</sql-query>

thanks,

Matthew Payne


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 2:48 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Nope, but you will sooner or later need also different SQL types in mappings, etc. For this reason, consider one of the many ways to solve this problem with several mapping files, overriding with XML entities, programatic configuration loading, two Hibernate XML configuration files, etc.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: I still think there might be some value in this.
PostPosted: Tue Jul 27, 2004 6:08 pm 
Beginner
Beginner

Joined: Mon Mar 22, 2004 9:37 am
Posts: 22
Location: Willow Grove, PA
Consider the following:
-we only use native sql querys when we need to.
-in mapping files, we avoid refering to sql types, just property types/names.
-auto schema generation is only used to create developer starting points.
-Actual Sql creation scripts are kept separate for each target database.

This way, a string property might be (varchar, varchar2, long, or text) underneath, but the mapping is still the same.

Right now the only place we are breaking database independence is the occational native sql command.

The ability to have the sql-query with a dialect parameter would give the flexiblity of native sql, but allow you to easliy step back in line and support you (mysql, sql-server, and oracle targets..).

I think I alot of people use hibernate with the intent of database independence. Is it possible that a section of the faq be dedicated to gottcha's/how to stay flexible with multiple database targets?

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 6:10 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
We don't want to make configuration options any more complicated. All the features are there and I know that many people simply use XML entities or different mapping files or different configuration files to solve this problem. Yes, it would be nicer, but its not worth the cost.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: okay I understand
PostPosted: Tue Jul 27, 2004 6:26 pm 
Beginner
Beginner

Joined: Mon Mar 22, 2004 9:37 am
Posts: 22
Location: Willow Grove, PA
Would you say it sounds resonable to keep all native querys in a single mapping document that included based on a property in the build script?

Thanks,

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 6:41 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
For example.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: re: example
PostPosted: Tue Jul 27, 2004 7:15 pm 
Beginner
Beginner

Joined: Mon Mar 22, 2004 9:37 am
Posts: 22
Location: Willow Grove, PA
I guess with spring and its property place holder thing you could do something like this in the applicationContext.

...
<value>com/diamondip/ipcontrol/model/DnsView.hbm.xml</value>
<value>com/diamondip/ipcontrol/model/DnsZone.hbm.xml</value>
<value>com/diamondip/ipcontrol/model/LogCategoryDictionary.hbm.xml</value>
<value>com/diamondip/ipcontrol/model/LogChannel.hbm.xml</value>
<value>com/diamondip/ipcontrol/model/${native-querys}.hbm.xml</value>


here ${native-querys} will be set by a property.

Otherwise, you could achive the same effect in ant with a property value containing which file to copy into the target.

With either of these solutions all native querys are kept in one mapping document vs. being next to the objects that they are related to.

I guess thats fine. Having them in one place might keep them from sneaking up on you.

Matt


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.