-->
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: PATINDEX IN HIBERNATE?
PostPosted: Thu Jun 22, 2006 3:46 am 
Beginner
Beginner

Joined: Mon Jan 30, 2006 2:28 am
Posts: 47
Location: INDIA
Hi

Is any Function PATINDEX Available in Hibernate? or how can find the index of searching query using HIBERNATE QUERY?

Thanks
edward

_________________
A.Edward Durai
"The things which are impossible with men are possible with God."


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 12:21 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It's not in any of the dialects yet. You can either use SQL query to make use of it, or edit your dialect file and rebuild your hibernate jar. Those files are in org/hiberate/dialect, just add a line like
Code:
registerFunction( "patindex", new StandardSQLFunction("patindex") );
to the constructor of the dialect you use.

There are other string-searching methods provided. Have a look in the ref docs section 14.9, "Expressions", for a list.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 12:55 am 
Beginner
Beginner

Joined: Mon Jan 30, 2006 2:28 am
Posts: 47
Location: INDIA
Excuse me,

Could You explain step by step. It's very much helpful for me. Because I am a beginner of Hibernate

Thanks

_________________
A.Edward Durai
"The things which are impossible with men are possible with God."


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 1:03 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You have two options. The first is to write your query as an SQL query instead of an HQL query.
Code:
Query q = session.createSQLQuery("select patindex('%yourstring%', YourColumn) from YourTable");

The second is to download the source code for Hibernate, edit the appropriate Dialect file (as pointed to by the hibernate.dialect property in your hibernate.cfg.xml file), add the registerFunction line I posted earlier, and rebuild the hibernate jar. For example, if your hibernate.cfg.xml file includes this line:
Code:
  <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
Then you'll edit org/hibernate/dialect/MySQLDialect.java.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 7:47 am 
Beginner
Beginner

Joined: Mon Jan 30, 2006 2:28 am
Posts: 47
Location: INDIA
Hi, It's working fine Now.

I have one more doubt.

My database contain xml format data like

1 <ISSUELIST data_1="23" data_34="34">
2 <ISSUELIST data_1="20" data_34="34">

I want to fetch data data_1

my expected result is
===============
1 data_1 23
2 data_1 20
===============

Using patindex I have found the position.

How can i fetch the value of data_1 using Hibernate query.

Thanks
edward

_________________
A.Edward Durai
"The things which are impossible with men are possible with God."


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.