-->
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: Stored Procedure remap result
PostPosted: Tue Jul 28, 2009 11:30 am 
Newbie

Joined: Tue Jul 28, 2009 10:58 am
Posts: 2
I am using Hibernate annotations with a simple Entity. I'm trying to test a stored procedure that brings back a different column name than the one mapped in my entity class. I have both a mapping class and a mapping file for the same entity. I get the exception "com.microsoft.sqlserver.jdbc.SQLServerException: The column name portfoli1_0_0_ is not valid" whenever I try to add a return-property to my mapping xml.

Here is my code
Code:
@Entity
@Table(name = "portfolio")
public class PortfolioEntity {

    @Id
    @GeneratedValue
    public int portfolioId;

    private String portfolioName;

    public PortfolioEntity() {
    }

    public int getPortfolioId() {
        return portfolioId;
    }

    public void setPortfolioId(int portfolioId) {
        this.portfolioId = portfolioId;
    }

    public String getPortfolioName() {
        return portfolioName;
    }

    public void setPortfolioName(String portfolioName) {
        this.portfolioName = portfolioName;
    }   
}

Code:
<hibernate-configuration>
    <session-factory>
        ...
        <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
        <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
        <!-- Mapping files -->
        <mapping class="com.persistence.domain.PortfolioEntity"/>
        <mapping file="com/persistence/domain/Portfolio.xml"/>
    </session-factory>
</hibernate-configuration>

Portfolio.xml
Code:
<hibernate-mapping>
    <sql-query name="spSelectPortfoliosBetweenIds" callable="true">
        <return alias="portfolio" class="com.artisan.persistence.domain.PortfolioEntity">
            <return-property name="portfolioName" column="pName"/>
        </return>
        { call spSelectPortfoliosBetweenIds(:portfolioId, :underId) }
    </sql-query>
</hibernate-mapping>


My stored proc returns a column name of "pName". If I change the proc to return "portfolioName" and remove the return-property from my sql-query it works fine. Also, if I annotate my Entity class with @Column(name="pName") it works. However I want to be able to use "portfolioName" for regular queries, and other names for procs.


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.