-->
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.  [ 25 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Mapping mssql stored procedures
PostPosted: Fri Feb 11, 2005 2:07 pm 
Regular
Regular

Joined: Wed Jan 19, 2005 4:52 pm
Posts: 61
Location: Kansas City, USA
Can someone point me in the right direction of an example of how to map a stored procedure in hibernate, I know it can be done in 3 but I am not sure how.

Thanks
Tim


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 10:21 am 
Regular
Regular

Joined: Wed Jan 19, 2005 4:52 pm
Posts: 61
Location: Kansas City, USA
Is there anybody that can assist me in this? The documentation is not there yet, and I am looking at the source to try to figure it out but that is not helping either. Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 5:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look in CustomSQLTest and SQLTest and their related mapping files.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 10:19 am 
Regular
Regular

Joined: Wed Jan 19, 2005 4:52 pm
Posts: 61
Location: Kansas City, USA
What package are these classes in, I looked through the project and can not locate them. I am using 3.0 B4.

Thanks
Tim


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 10:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
its in the unit tests. if not part of the main distribution then it is in cvs.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 10:23 am 
Regular
Regular

Joined: Wed Jan 19, 2005 4:52 pm
Posts: 61
Location: Kansas City, USA
They are in the test package but where have they been rolled in on the src? Or have they?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 10:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
dont understand that sentence.

they are in CVS

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 17, 2005 12:44 pm 
Regular
Regular

Joined: Wed Jan 19, 2005 4:52 pm
Posts: 61
Location: Kansas City, USA
Still having a little trouble with this, what method would I use to run a stored procedure? Here is my hbm file:

Code:
<hibernate-mapping package="com.nationsholding.xOps.common.model.StoredProcedures">

    <class name="OrderCreate">
       <id name="id" type="long">
            <generator class="native"/>
        </id>
      <property name="message" type="java.lang.String"/>
        <property name="executerEntityId" type="java.lang.String" />
          <property name="executerEntityHierarchyId" type="java.lang.String" />
          <property name="executerCompanyId" type="java.lang.String"/>
          <property name="orderId" type="java.lang.String"/>
          <property name="idOrderType" type="java.lang.String" />
          <property name="idOrderOrigination" type="java.lang.String" />
          <property name="entityIdCustomer" type="java.lang.String" />
          <property name="entityIdVendor" type="java.lang.String" />
          <property name="requestSubject" type="java.lang.String" />
          <property name="requestDescription" type="java.lang.String" />
          <property name="address1" type="java.lang.String" />
          <property name="address2" type="java.lang.String" />
          <property name="city" type="java.lang.String" />
          <property name="state" type="java.lang.String" />
          <property name="zip" type="java.lang.String" />
          <property name="zip4" type="java.lang.String" />
          <property name="valid" type="java.lang.Short" />
          <property name="latitude" type="java.lang.Long" />
          <property name="longitude" type="java.lang.Long" />
          <property name="referenceNumber" type="java.lang.String" />
          <property name="parcelNumber" type="java.lang.String" />
          <property name="entityIdSource" type="java.lang.String" />
          <property name="referenceNumberSource" type="java.lang.String" />
          <property name="dateTimeReceived" type="java.sql.Timestamp" />
          <property name="idOrderPriority" type="java.lang.String" />
          <property name="orderNumber" type="java.lang.String" />
       
   <sql-insert callable="true">{call p_order_create (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}</sql-insert>
     
    </class>
   
</hibernate-mapping>


This is the POJO class for this mapping:

Code:
public class OrderCreate
    implements Serializable, XOpsOrder
{
   /** The cached hash code value for this instance.  Settting to 0 triggers re-calculation. */
    private int hashValue = 0;
   /** The composite primary key value. */
    private Long id;
   
    private String message;
    private String orderId;
    private String executerEntityId;
    private String executerEntityHierarchyId;
    private String executerCompanyId;
      private String idOrderType;
      private String idOrderOrigination;
      private String entityIdCustomer;
      private String entityIdVendor;
      private String requestSubject;
      private String requestDescription;
      private String address1;
      private String address2;
      private String city;
      private String state;
      private String zip;
      private String zip4;
      private Short valid;
      private Long latitude;
      private Long longitude;
      private String referenceNumber;
      private String parcelNumber;
      private String entityIdSource;
      private String referenceNumberSource;
      private Timestamp dateTimeReceived;
      private String idOrderPriority;
      private String orderNumber;

    public OrderCreate()
    {
    }

    /**
     * Constructor of Site instances given a simple primary key.
     * @param siteId
     */
    public OrderCreate(java.lang.Long id)
    {
        this.setId(id);
    }
    public java.lang.Long getId()
    {
        return id;
    }

    /**
     * Set the simple primary key value that identifies this object.
     * @param siteId
     */
    public void setId(java.lang.Long id)
    {
        this.hashValue = 0;
        this.id = id;
    }
    /**
    * @return Returns the message.
    */
   public String getMessage() {
      return message;
   }
   /**
    * @param message The message to set.
    */
   public void setMessage(String message) {
      this.message = message;
   }
   /**
    * @return Returns the orderId.
    */
   public String getOrderId() {
      return orderId;
   }
   /**
    * @param orderId The orderId to set.
    */
   public void setOrderId(String orderId) {
      this.orderId = orderId;
   }
   /**
    * @return Returns the address1.
    */
   public String getAddress1() {
      return address1;
   }
   /**
    * @param address1 The address1 to set.
    */
   public void setAddress1(String address1) {
      this.address1 = address1;
   }
   /**
    * @return Returns the address2.
    */
   public String getAddress2() {
      return address2;
   }
   /**
    * @param address2 The address2 to set.
    */
   public void setAddress2(String address2) {
      this.address2 = address2;
   }
   /**
    * @return Returns the city.
    */
   public String getCity() {
      return city;
   }
   /**
    * @param city The city to set.
    */
   public void setCity(String city) {
      this.city = city;
   }
   /**
    * @return Returns the datetimeReceived.
    */
   public Timestamp getDateTimeReceived() {
      return dateTimeReceived;
   }
   /**
    * @param datetimeReceived The datetimeReceived to set.
    */
   public void setDateTimeReceived(Timestamp dateTimeReceived) {
      this.dateTimeReceived = dateTimeReceived;
   }
   /**
    * @return Returns the entityId.
    */
   public String getEntityIdSource() {
      return entityIdSource;
   }
   /**
    * @param entityId The entityId to set.
    */
   public void setEntityIdSource(String entityId) {
      this.entityIdSource = entityId;
   }
   /**
    * @return Returns the entityIdCustomer.
    */
   public String getEntityIdCustomer() {
      return entityIdCustomer;
   }
   /**
    * @param entityIdCustomer The entityIdCustomer to set.
    */
   public void setEntityIdCustomer(String entityIdCustomer) {
      this.entityIdCustomer = entityIdCustomer;
   }
   /**
    * @return Returns the entityIdVendor.
    */
   public String getEntityIdVendor() {
      return entityIdVendor;
   }
   /**
    * @param entityIdVendor The entityIdVendor to set.
    */
   public void setEntityIdVendor(String entityIdVendor) {
      this.entityIdVendor = entityIdVendor;
   }
   /**
    * @return Returns the executerCompanyId.
    */
   public String getExecuterCompanyId() {
      return executerCompanyId;
   }
   /**
    * @param executerCompanyId The executerCompanyId to set.
    */
   public void setExecuterCompanyId(String executerCompanyId) {
      this.executerCompanyId = executerCompanyId;
   }
   /**
    * @return Returns the executerEntityHierarchyId.
    */
   public String getExecuterEntityHierarchyId() {
      return executerEntityHierarchyId;
   }
   /**
    * @param executerEntityHierarchyId The executerEntityHierarchyId to set.
    */
   public void setExecuterEntityHierarchyId(String executerEntityHierarchyId) {
      this.executerEntityHierarchyId = executerEntityHierarchyId;
   }
   /**
    * @return Returns the executerEntityId.
    */
   public String getExecuterEntityId() {
      return executerEntityId;
   }
   /**
    * @param executerEntityId The executerEntityId to set.
    */
   public void setExecuterEntityId(String executerEntityId) {
      this.executerEntityId = executerEntityId;
   }
   /**
    * @return Returns the idOrderOrigination.
    */
   public String getIdOrderOrigination() {
      return idOrderOrigination;
   }
   /**
    * @param idOrderOrigination The idOrderOrigination to set.
    */
   public void setIdOrderOrigination(String idOrderOrigination) {
      this.idOrderOrigination = idOrderOrigination;
   }
   /**
    * @return Returns the idOrderPriority.
    */
   public String getIdOrderPriority() {
      return idOrderPriority;
   }
   /**
    * @param idOrderPriority The idOrderPriority to set.
    */
   public void setIdOrderPriority(String idOrderPriority) {
      this.idOrderPriority = idOrderPriority;
   }
   /**
    * @return Returns the idOrderType.
    */
   public String getIdOrderType() {
      return idOrderType;
   }
   /**
    * @param idOrderType The idOrderType to set.
    */
   public void setIdOrderType(String idOrderType) {
      this.idOrderType = idOrderType;
   }
   /**
    * @return Returns the latitude.
    */
   public Long getLatitude() {
      return latitude;
   }
   /**
    * @param latitude The latitude to set.
    */
   public void setLatitude(Long latitude) {
      this.latitude = latitude;
   }
   /**
    * @return Returns the longitude.
    */
   public Long getLongitude() {
      return longitude;
   }
   /**
    * @param longitude The longitude to set.
    */
   public void setLongitude(Long longitude) {
      this.longitude = longitude;
   }
   /**
    * @return Returns the orderNumber.
    */
   public String getOrderNumber() {
      return orderNumber;
   }
   /**
    * @param orderNumber The orderNumber to set.
    */
   public void setOrderNumber(String orderNumber) {
      this.orderNumber = orderNumber;
   }
   /**
    * @return Returns the parcelNumber.
    */
   public String getParcelNumber() {
      return parcelNumber;
   }
   /**
    * @param parcelNumber The parcelNumber to set.
    */
   public void setParcelNumber(String parcelNumber) {
      this.parcelNumber = parcelNumber;
   }
   /**
    * @return Returns the referenceNumber.
    */
   public String getReferenceNumber() {
      return referenceNumber;
   }
   /**
    * @param referenceNumber The referenceNumber to set.
    */
   public void setReferenceNumber(String referenceNumber) {
      this.referenceNumber = referenceNumber;
   }
   /**
    * @return Returns the referenceNumberSource.
    */
   public String getReferenceNumberSource() {
      return referenceNumberSource;
   }
   /**
    * @param referenceNumberSource The referenceNumberSource to set.
    */
   public void setReferenceNumberSource(String referenceNumberSource) {
      this.referenceNumberSource = referenceNumberSource;
   }
   /**
    * @return Returns the requestDescription.
    */
   public String getRequestDescription() {
      return requestDescription;
   }
   /**
    * @param requestDescription The requestDescription to set.
    */
   public void setRequestDescription(String requestDescription) {
      this.requestDescription = requestDescription;
   }
   /**
    * @return Returns the requestSubject.
    */
   public String getRequestSubject() {
      return requestSubject;
   }
   /**
    * @param requestSubject The requestSubject to set.
    */
   public void setRequestSubject(String requestSubject) {
      this.requestSubject = requestSubject;
   }
   /**
    * @return Returns the state.
    */
   public String getState() {
      return state;
   }
   /**
    * @param state The state to set.
    */
   public void setState(String state) {
      this.state = state;
   }
   /**
    * @return Returns the valid.
    */
   public Short getValid() {
      return valid;
   }
   /**
    * @param valid The valid to set.
    */
   public void setValid(Short valid) {
      this.valid = valid;
   }
   /**
    * @return Returns the zip.
    */
   public String getZip() {
      return zip;
   }
   /**
    * @param zip The zip to set.
    */
   public void setZip(String zip) {
      this.zip = zip;
   }
   /**
    * @return Returns the zip4.
    */
   public String getZip4() {
      return zip4;
   }
   /**
    * @param zip4 The zip4 to set.
    */
   public void setZip4(String zip4) {
      this.zip4 = zip4;
   }
    /**
     * Implementation of the equals comparison on the basis of equality of the primary key values.
     * @param rhs
     * @return boolean
     */
    public boolean equals(Object rhs)
    {
        if (rhs == null)
            return false;
        if (! (rhs instanceof OrderCreate))
            return false;
        OrderCreate that = (OrderCreate) rhs;
        if (this.getId() != null && that.getId() != null)
        {
            if (! this.getId().equals(that.getId()))
            {
                return false;
            }
        }
        return true;
    }

    /**
     * Implementation of the hashCode method conforming to the Bloch pattern with
     * the exception of array properties (these are very unlikely primary key types).
     * @return int
     */
    public int hashCode()
    {
        if (this.hashValue == 0)
        {
            int result = 17;
            int IdValue = this.getId() == null ? 0 : this.getId().hashCode();
            result = result * 37 + IdValue;
            this.hashValue = result;
        }
        return this.hashValue;
    }

}



I am creating a DAO to "run" this stored procedure, passing it in the OrderCreate object. What method call do I use to "run it".

Thanks
Tim


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 17, 2005 1:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you dont call it directly. Hibernate does.

it is run when hibernate wants to perform an insert on your object.
which is done when you save the object via a hibernate session.

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 17, 2005 1:28 pm 
Regular
Regular

Joined: Wed Jan 19, 2005 4:52 pm
Posts: 61
Location: Kansas City, USA
so I would use something like this
Code:
try {
session.save(order);
}  catch (HibernateException ex) {
throw new XOpsException(ex);
}

passing it in the OrderCreate object as order.

Now how would I get the output from the stored procedure. The signature for the SP is :
Code:
CREATE PROCEDURE p_order_create
@output_message AS varchar(255) OUTPUT,
@executer_entity_id AS uniqueidentifier,
@executer_entity_hierarchy_id AS uniqueidentifier,
@executer_company_id AS uniqueidentifier,
@order_id AS uniqueidentifier OUTPUT,

@u_id_order_type AS uniqueidentifier,
@u_id_order_origination AS uniqueidentifier,
@entity_id_customer AS uniqueidentifier,
@entity_id_vendor AS uniqueidentifier,

@request_subject AS varchar(100) = NULL,
@request_description AS varchar(2000) = NULL,

@address_1 AS varchar(100) = '',
@address_2 AS varchar(100) = NULL,
@city AS varchar(50) = NULL,
@state AS char(2) = NULL,
@zip AS char(6) = '',
@zip4 AS char(4) = NULL,
@valid AS smallint = 0,
@latitude AS decimal(8,4) = NULL,
@longitude AS decimal(8,4) = NULL,

@reference_number AS varchar(50) = NULL,
@parcel_number AS varchar(50) = NULL,

@entity_id_source AS uniqueidentifier = NULL,
@reference_number_source AS varchar(50) = NULL,
@datetime_received AS datetime = NULL,
@u_id_order_priority as uniqueidentifier =null,

@order_number as varchar(12) =null



Thanks for all the help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 17, 2005 1:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
unfortunately at the moment the sequence of things are pretty strict for this.

if you enable debug log for org.hibernate.persister.entity you should get a log output showing you the sql uses for its inserts, updates, etc.
From that you should be able to deduce which parameters go where.
(remember to comment out your sql-insert as otherwise it will be that which hibernate will send to the log)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 18, 2005 10:32 am 
Regular
Regular

Joined: Wed Jan 19, 2005 4:52 pm
Posts: 61
Location: Kansas City, USA
So will hibernate automatically update my OrderCreate object with the output results? Or do these get returned via some other method. In the signature for the stored procesure there are two output fields, output_message at position 1 and order id at position 5. These are mapped in my hbm as seen in the code above and are getter and setter methods in the POJO. Upon the .save(Object) method will these outputs be populated in these methods of the object?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 18, 2005 2:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 19, 2005 10:02 am 
Regular
Regular

Joined: Wed Jan 19, 2005 4:52 pm
Posts: 61
Location: Kansas City, USA
Ok, how do I get those outputs back then?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 19, 2005 10:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
at the moment you can't.

add a jira request for it with a usecase then we can consider adding it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 25 posts ]  Go to page 1, 2  Next

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.