-->
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: longvarbinary and hibernate
PostPosted: Thu Jan 08, 2004 5:35 am 
Newbie

Joined: Thu Jan 08, 2004 5:12 am
Posts: 4
Hi,

I've got a small problem with a mapping file containing a column of type binary. I'm using an application called XPlanner which uses Hibernate 1.2 (AFAIK). I'm trying to get XPlanner/Hibernate to work with MS-SqlServer2000 and SqlServer2000 only supports binary-columns with a max size of 8000 while XPlanner calls for 1GB for this specific column.

Large columns are supported in SqlServer2000 using one of the following column types: ntext (unicode), text and image. ntext and text maps to the following JDBC-datatype: LONGVARCHAR and image maps to LONGVARBINARY.

So I've tried changing the column type in the mapping file from binary to text and also tried changing it from binary to longvarbinary. When I run an ant build script called install.db.schema provided by XPlanner I get the following error (both when using text and longvarbinary):

[java] 546 [main] INFO cirrus.hibernate.impl.DatastoreImpl - Mapping file: C:\javaapps\xplanner_0.5.2\xplanner\resources\mappings\Note.xml
[java] 593 [main] ERROR cirrus.hibernate.impl.DatastoreImpl - Could not compile the mapping document
[java] cirrus.hibernate.MappingException: Could not interpret type: longvarbinary
[java] at cirrus.hibernate.map.Value.getTypeFromXML(Value.java:174)
[java] at cirrus.hibernate.map.Value.typeFromXML(Value.java:154)
[java] at cirrus.hibernate.map.Value.<init>(Value.java:71)
[java] at cirrus.hibernate.map.Value.<init>(Value.java:128)
[java] at cirrus.hibernate.map.PersistentClass.propertiesFromXML(PersistentClass.java:82)
[java] at cirrus.hibernate.map.RootClass.<init>(RootClass.java:239)
[java] at cirrus.hibernate.map.Root.<init>(Root.java:145)
[java] at cirrus.hibernate.impl.DatastoreImpl.store(DatastoreImpl.java:103)
[java] at cirrus.hibernate.impl.DatastoreImpl.storeFile(DatastoreImpl.java:68)
[java] Error creating schema Could not interpret type: longvarbinary
[java] cirrus.hibernate.MappingException: Could not interpret type: longvarbinary
[java] at cirrus.hibernate.map.Value.getTypeFromXML(Value.java:174)
[java] at cirrus.hibernate.map.Value.typeFromXML(Value.java:154)
[java] at cirrus.hibernate.map.Value.<init>(Value.java:71)
[java] at cirrus.hibernate.map.Value.<init>(Value.java:128)
[java] at cirrus.hibernate.tools.SchemaExport.main(SchemaExport.java:259)

Any suggestions how to solve this would be highly appreciated as things have sort of ground to a halt due to the problem above.

--norgie


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 5:36 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Don't change the mapping type, but the "sqltype" of the column?

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 6:00 am 
Newbie

Joined: Thu Jan 08, 2004 5:12 am
Posts: 4
I'm completely and utterly a newbie regarding Hibernate so please have patience with me.

This is the original line in the mapping file

<property name="file" type="binary" length="1000000000"/>

What I've tried to do is to change 'type=binary' to e.g. 'type=text', 'type=image' or 'type=longvarbinary' to no avail.

When you say change the 'slqtype' of the column, do you mean in the physical database or are you referring to an argument to be added to the <property .../> line above? Or something else?

-- norgie


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 8:50 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Try:

<property name="file" type="binary" sql-type="IMAGE" length="1000000000"/>

or ask the author of xplanner which SQL type you should use for MS SQL server. The default SQL type for the specific database dialect can be found in the Hibernate dialect source, but I'd need the exact Hibernate version to look that up.

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 11:41 am 
Newbie

Joined: Thu Jan 08, 2004 5:12 am
Posts: 4
>> <property name="file" type="binary" sql-type="IMAGE" length="1000000000"/>

This is great. I'll try this and see if it works.

--norgie


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 11:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Actually it should be:


Code:
<property name="file" type="binary" >
     <column name="file" sql-type="IMAGE" />
</property>


(or perhaps sql-type="IMAGE(1000000000)")


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 12:14 pm 
Newbie

Joined: Thu Jan 08, 2004 5:12 am
Posts: 4
Thanks Gavin. It worked like a charm!"

Only problem now is that 'file' is a reserved word in SqlServer, so the create table script for the table containing this column is rejected.

Would it be possible to do something like this?

<property name="file" type="binary" length="1000000000">
<column name="thefile" sql-type="IMAGE" />
</property>

I.e. define a mapping between the property 'file' and the column it refers to? If so, that would solve problems pertaining to other reserved words in SqlServer, e.g. 'name'.

--norgie


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Sure, just have a look at the DTD and see what is allowed for <property> and <column>. It's pretty much self explanatory.

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


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.