Hi
I've got Hibernate 3.1.3 and mySQL 5.0.18
writing stored procedures with EMS Manager
SP: name sp_proba(myname)
Code:
BEGIN
select clients_id, name, address from clients where name =myname;
END
hbm.file
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="ee.wallis.crm.win.beans.AAA" table="AAA">
<id name="Id" type="long" column="clients_id">
<generator class="assigned" />
</id>
<property name="name" type="string" column="name" />
<property name="address" type="string" column="address" />
</class>
<sql-query name="sp_deliv" callable="true">
<return class="ee.wallis.crm.win.beans.AAA">
<return-property name="Id" column = "clients_id"/>
<return-property name="name" column = "name"/>
<return-property name="address" column = "address"/>
</return>
{call sp_proba(:myname) }
</sql-query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Code:
Query query = session.getNamedQuery("sp_deliv");
query.setString("myname", String.valueOf("Tehnomet"));
List<AAA> result = query.list();
for(AAA client: result){
System.out.println("Start: " + client.getName());
System.out.println("Start: " + client.getAddress());
}
Be sure that you got class AAA.
If I use SP like filter - it works. When I try update somethink in SP body like
Code:
BEGIN
update projects a, `deliveries` b, `activities` c set c.status_code = newName
where (c.status_code=oldName) AND (b.deliveries_id = deliveryID)
AND (a.projects_id = b.projects_id) AND (b.deliveries_id = c.deliveries_id);
select clients_id, name, address from clients where name =myname;
END
it ignores update part and execute select part.
In manual was written that
Quote:
The stored procedure/function must return a resultset as the first out-parameter to be able to work with Hibernate
is it mean that no any possibility update via SP and Hibernate?
one more thing.
manual give
Quote:
Recommended call form is standard SQL92: { ? = call functionName(<parameters>) } or { ? = call procedureName(<parameters>}. Native call syntax is not supported.
But if I mapping with "{? = call" - program request function. Is that specific of mySQL?