-->
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.  [ 1 post ] 
Author Message
 Post subject: Unsupported (non-standard) functions (RegisterFunction)
PostPosted: Mon Oct 29, 2007 9:11 am 
Newbie

Joined: Thu Oct 25, 2007 5:45 am
Posts: 1
Location: Voronezh, Russia
Good day!

I need to use some unsupported (Oracle) functions, for example, LOCATE. In the Oracle9Dialect this function declared in the following way:
Code:
registerFunction( "locate", new SQLFunctionTemplate( Hibernate.INTEGER, "instr(?2,?1)" ) );


I believe that this should mean:
Code:
select instr('programmer', 'program') === select locate('program', 'programmer');


But I can't to use this feature!

Assume that I have a table:
Code:
create table test_1 (id int, description varchar(255))


I need to make a query like this:
Code:
select id, locate(description, 'program') from table_test;


To do so, I use the following class:
Code:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.Formula;

@Entity
@Table(name = "TEST_1")
public class Test_1_DTO {
   public Test_1_DTO() {
      super();
   }   
   
   private Integer id;
   private String desc;

   @Column(name = "DESCRIPTION", length = 255)
   @Formula(value = "locate(description, 'program')")
   public String getDesc() {
      return desc;
   }

   public void setDesc(String desc) {
      this.desc = desc;
   }

   @Id
   @Column(name = "ID")
   @GeneratedValue
   public Integer getId() {
      return id;
   }

   public void setId(Integer id) {
      this.id = id;
   }

   public Test_1_DTO(Integer id, String desc) {
      super();
      this.id = id;
      this.desc = desc;
   }
}


For reception of sample I execute:
Code:
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;

...

AnnotationConfiguration aconf = new AnnotationConfiguration();
Configuration cfg = aconf.configure("hibernate.cfg.xml");
SessionFactory sessionFactory = cfg.buildSessionFactory();

Session session =  sessionFactory.openSession();
session.beginTransaction();
Test_1_DTO obj = session.load(Test_1_DTO.class, 1);
session.getTransaction().commit();


I expect to receive:
Code:
select test_1_dto0_.ID as ID0_0_, instr('program', test_1_dto0_.description) as formula0_0_ from TEST_1 test_1_dto0_ where test_1_dto0_.ID=?


Instead of this the result is:
Code:
select test_1_dto0_.ID as ID0_0_, test_1_dto0_.ddd as ddd0_0_, locate(test_1_dto0_.description, 'program') as formula0_0_ from TEST_1 test_1_dto0_ where test_1_dto0_.ID=?


I.e. LOCATE not replaced by INSTR!
What am I doing wrong?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.