-->
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.  [ 8 posts ] 
Author Message
 Post subject: Dynamic Dialect
PostPosted: Mon Jan 24, 2005 11:06 am 
Beginner
Beginner

Joined: Fri Oct 22, 2004 4:47 pm
Posts: 22
We currently have our session factory setup for the MSSQL dialect. I have come across a situation where we want to obtain data from one of our legacy systems, which is using a proprietary sql database. I am able to run query's on it by passing a JDBC connection into the session, and it seems to work OK for the most part under the MSSQL dialect.

The problem I am having is that the database does not support "select top", so when I am doing setMaxResults() on my criteria query, the DB driver is throwing an error. I guess I have a couple of questions:

1. Is there a dialect I can use that will limit the number of rows that are brought back on the list()? For example, the query executes and returns 500 rows, but only have hibernate populate the list with the first 50 of these results.

2. If the answer to question #1 is yes, then is there a way to change the dialect progamatically through the session, or in the mapping file for this class?

Thanks,

Paul Zepernick

Below is the information on my hibernate install:






Hibernate version:
2.1.7

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="com.iws.model.workflow.eci.search.Patient" table="PATIENT">

<composite-id>
<key-property name="punbr" column="PUNBR" type="string" />
<key-property name="grnbr" column="GRNBR" type="string"/>
<key-property name="essn" column="ESSN" type="string"/>
<key-property name="seq" column="SEQ" type="string"/>
</composite-id>

<property name="lname"
column="LNAME"
update="false"
insert="false"
type="string"/>

<property name="ftname"
column="FTNAME"
update="false"
insert="false"
type="string"/>

<property name="addr1"
column="ADDR1"
update="false"
insert="false"
type="string"/>

<property name="city"
column="CITY"
update="false"
insert="false"
type="string"/>

<property name="state"
column="STATE"
update="false"
insert="false"
type="string"/>

<property name="zip"
column="ZIP"
update="false"
insert="false"
type="string"/>
</class>

</hibernate-mapping>


Name and version of the database you are using:
Proprietary database. DBC/FS


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 11:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Why don't you just use a second SessionFactory with GenericSqlDialect


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 11:40 am 
Beginner
Beginner

Joined: Fri Oct 22, 2004 4:47 pm
Posts: 22
OK, GenericSqlDialect will work for my situation then?


How would I go about creating a new session factory? Would I just add another <session-factory></session-factory> block to the hibernate.cfg.xml?

If so, do I have to build the session factory differently? Here is how I am currently building it:

Code:

    /**
     *Build the hibernate session factory
     *
     */

    public void init(ServletConfig configs){
        try {
            System.out.println("Initializing Hibernate");
            hibernateConfigruation = new Configuration();
            sessionFactory = hibernateConfigruation.configure().buildSessionFactory();
            System.out.println("Finished Initializing Hibernate");
        } catch (HibernateException e) {
            System.out.println("FATAL ERROR: HIBERNATE FAILED TO START");
            e.printStackTrace();
        }
    }




Once the session factory is built, how do I tell hibernate to give me a session from the factory I want?

Thanks,

Paul


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 11:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Just use two config xml files


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 3:24 pm 
Beginner
Beginner

Joined: Fri Oct 22, 2004 4:47 pm
Posts: 22
OK, thanks for the help.....

One more question through. I have the second SessionFactory loading now, but how do I tell the config file to use the GenericDialect. I do not see it in this list:

http://www.hibernate.org/hib_docs/refer ... l-dialects

Thanks,

Paul


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 3:32 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Did you try to set it or simply not use a dialect?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 3:34 pm 
Beginner
Beginner

Joined: Fri Oct 22, 2004 4:47 pm
Posts: 22
I tried to set it.

<property name="dialect">GenericSqlDialect</property>

It did not throw any errors, but I just wanted to make sure that this was the proper format for the Dialect.

Thanks,

Paul


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 3:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use the full class name of the dialect.


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