-->
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: TEXT, NTEXT data types
PostPosted: Sun Nov 14, 2004 1:01 am 
Newbie

Joined: Wed Nov 10, 2004 6:34 am
Posts: 7
Hibernate version: 2.1.6

We develop an application that works across SQL Server, Postgres and Oracle and are planning to use hibernate for this.

1. How does one specify a column of type "text" or "ntext" as allowed by SQL Server and Postgres? I used Middlegen to reverse engineer the mapping files and it has put a length=-1 for columns of type "text". What do I replace that with?

2. The same columns above have to be mapped to "LONG" type for Oracle. Is it possible to have a single set of mapping files or 1 per database? We plan to add support for other databases such as Cloudscape and Interbase in the future so will prefer 1 set of mapping files.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 14, 2004 5:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Middlegen gets its information from the JDBC driver. This also applies in the case of the value for the length. What is the JDBC driver telling you when you for these types of columns?

Middlegen has a plugable type mapper interface so you can create you own to provide whatever types you like for the database type the JDBC driver provides. You will need multiple mapping documents unless you consider wrapping the type into a hibernate user type. The user type can then deal with the different databases within the code.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 1:32 am 
Newbie

Joined: Wed Nov 10, 2004 6:34 am
Posts: 7
My plan is to use Middlegen once to get the mapping files as a start. From then I will modify the *hbm.xml files by hand. My question is what should I set the "type" in the *hbm.xml files for ntext/text data types? (For this instance lets assume I was writing the mapping files by hand).

Once I do the right thing above, will schemaexport generate appropriate ddl script if I change the dialect? ie will it appropriately create a column of type "ntext" for Sql server and "text" for Postgresql?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 2:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The mapping document allows you to map the types approrpriately. The very basic method is to supply the java type, eg, java.lang.String as the type and this is used in combination with the JDBC driver. I don't know the information for the databases and types your after, so to answer you question you need to ask yourself a question- what java type does the JDBC driver expect for the database column type. The docs for the driver should tell you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 3:47 am 
Newbie

Joined: Wed Nov 10, 2004 6:34 am
Posts: 7
I am trying to support Postgres, SQL Server and Oracle.

I have 2 columns. summary (max length 200 chars) and detail (which I would like to be as long as possible)

Both the columns have java type String.

For the "detail" column I want schemaexport to generate the following

1. Postgres: detail TEXT
2. SQL Server: detail NTEXT
3. Oracle: detail LONG

- "LONG" in Oracle can be read as a String.

For the summary column (where length is specified) I want

1. Postgres: summary VARCHAR(200)
2. SQL Server: summary VARCHAR(200)
3. Oracle: summary VARCHAR2(200)

What would I need to do in the hbm file?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 4:37 am 
Newbie

Joined: Wed Nov 10, 2004 6:34 am
Posts: 7
I think I found a way.

In the mapping file I can specify the sql-type using the column tag to something like {TEXT}. Using ant's filtering capability I set this to be NTEXT, TEXT or LONG depending on the database.

Then schemaexport will generate correct ddl.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 16, 2004 8:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Yes post processing the HBM is what a I do from time to time.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.