0

Possible Duplicate:
Calling a Stored Procedure in Hibernate

I have the following problem: I can not call a stored procedure in java

what I did was this:

create a class that implements serializable semaforoBO call and add the following

@Entity
@NamedNativeQuery(
name="CalculoSemaforo",
query = "exec CalculoSemaforo codigo,fecha",
callable=true,
resultClass=char.class
)
public class SemaforoBO implements Serializable{
//code
}

the name of the stored procedure is CalculoSemaforo and has two input variables returning a char. Then within SemaforoBO there a function that does the following:

public char semaforo(){
        DBTenant dbTenant = new DBTenant();
        Session sess;
        try {
            sess = dbTenant.getTenantSession();
            Query query =sess.getNamedQuery("CalculoSemaforo");
            query.setString("codigo", this.codigoarticulo);
            query.setLong("fecha",this.fecha);
            sem = (Character) query.uniqueResult();
        }
        catch(NullPointerException e)
        {
            sem = 'x';
        }
        return sem;
}

but it gives me a excepccion org.hibernate.MappingException: Named query not known: CalculoSemaforo

any idea how this solution Thanks

1

1 Answer 1

1

I found an alternative to call the stored procedure using hibernate without map or you have to have to rely on a class to call

DBTenant dbTenant = new DBTenant();
        Session sess;
        try {
            sess = dbTenant.getTenantSession();
            Query qry = sess.createSQLQuery("{ call Iturria.dbo.CalculoSemaforo2(?,?) }");
            qry.setString(0, this.codigoarticulo);
            qry.setLong(1, this.fecha);
            sem = (Character) qry.uniqueResult();
        }
        catch(NullPointerException e)
        {
            sem = 'y';
            return sem;
        }

thanks for response

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.