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.  [ 5 posts ] 
Author Message
 Post subject: How to specify default markers in prepared stmts?
PostPosted: Fri Feb 04, 2005 8:26 am 
Newbie

Joined: Tue Jun 29, 2004 9:35 am
Posts: 6
Hi,
With reference to this unanswered post

http://forum.hibernate.org/viewtopic.ph ... ht=xmltype

I have a class where one member is mapped by a UserType to the Oracle XMLType
Code:
<hibernate-mapping package="com.blah.proto.hbm.persistent">
   <class name="XMLDocument" table="XML_DOCUMENT" mutable="true" lazy="false" >
      <id name="id" type="long" column="ID" length="20">
       <generator class="native"/>
      </id>
      <property name="internalId" type="string" column="INTERNAL_ID" length="37" not-null="true" />
      <property name="creationTimeStamp" type="timestamp" column="CREATION_TIMESTAMP" not-null="true"/>
      <property name="xmlDoc" type="com.blah.proto.hbm.persistent.usertypes.XMLTypeUserType" column="XML_DOC" not-null="true" />
      <property name="docName" type="string" column="DOC_NAME" not-null="true" />
   </class>
</hibernate-mapping>


During object creation hibernate makes this insert statement
Code:
insert into XML_DOCUMENT (ID, INTERNAL_ID, XML_DOC, DOC_NAME) values (?, ?, ?, ?)


The insert fails (as does update) with something like "expecting NUMBER got LONG"
If I step through and replace the third ? with xmltype(?) then I can happily insert and update XMLTypes all day long.

My question is :
Is there existing functionality allowing me to set a value in XMLTypeUserType which tells hibernate a custom value to use in place of ?, by calling
Code:
Insert.addColumn(columnName, customMarker);

instead of
Code:
Insert.addColumn(columnName);


If not I was going to hack hibernate 2.8 to do what I want.
From what I've seen this means making changes to the generateXXXString methods in both net.sf.hibernate.persister.EntityPersister and net.sf.hibernate.persister.NormalizedEntitypersister. Is there anything else I need to be aware of?

I couldn't find anything like this in hibernate 3.0 either (although I may have just not seen it), and it looks like it won't be as easy anyway because the equivalent generateXXXString methods are in the BasicEntityPersister super class, so they have no visibility of the column types.

Is this the kind of configuration that Hibernate should be expected to support, or is it something that is only necessary because of rare vendor specific extensions like XMLType?

Cheers

Simon


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 8:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
In Hibernate3, use <sql-insert> and <sql-update>. See the manual.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 8:40 am 
Newbie

Joined: Tue Jun 29, 2004 9:35 am
Posts: 6
Hi Gavin,
Thanks for the amazingly quick reply, thats just was I was looking for :) Sorry i didn't RTM...

Because 3 is in Beta I'd still need to do this in 2.8 initially - will updating the two EntityPersister classes be enough, or do I need to change more?
It would be a very specific modification for XMLType only.

Cheers

Simon


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 8:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Nah, should be easy enough to override the SQL generation methods in a custom persister.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 9:30 am 
Newbie

Joined: Tue Jun 29, 2004 9:35 am
Posts: 6
Yeah I'd seen that but I thought it meant I'd need to write a custom persister for each class that used a field mapped to XMLType (with the associated changes required whenever I updated the class).. so through laziness I was hoping there was a better way, even if it meant changing hibernate :)

If you wanted to add functionality to generate valid sql statements specifically for creating and updating classes with a member mapped to XMLType, for use in 1..n different classes in Hibernate 2.8, how would you do it? Bearing in mind its a filler until we can move to 3 - custom persisters or a change to Hibernate?

Cheers


Simon


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