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.