[
http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-451?pag...
]
Tomaž commented on HSEARCH-451:
-------------------------------
1) With out @SqlResultSetMapping this issue could be solved only with pure jdbc
connection(Connection conn = ((HibernateEntityManager) emAris).getSession().connection();)
but this method is deprecated.
2) To realy solved this is to use SqlResultSetMapping and this annotation can be applied
to any entity class
@Entity
@Table(name = "organizacije")
@SqlResultSetMapping(name="orgScalar",
columns={@ColumnResult(name="id"), @ColumnResult(name="k"),
@ColumnResult(name="t")})
public class OrganizacijeEntity
....
and then in code:
String sql = "SELECT organizacije.id, koda.vrednost AS k, tip.vrednost AS t "
+ "FROM organizacije "
+ "LEFT JOIN sif_kodorg AS koda ON koda.id=organizacije.koda "
+ "LEFT JOIN sif_tiporg AS tip ON tip.id=organizacije.tip_org "
+ "WHERE organizacije.id="+orgId;
Query arisQuery = emAris.createNativeQuery(sql,
"orgScalar");
Regards, Tomaz
NativeQuery alias on column
----------------------------
Key: HSEARCH-451
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-451
Project: Hibernate Search
Issue Type: Bug
Components: query
Affects Versions: 3.2.0.CR1
Environment: OS: Win XP
Java: 1.6
Hibernate 3.2.5.ga
MySQL: 5.1
Reporter: Tomaž
Priority: Blocker
Original Estimate: 1 day
Remaining Estimate: 1 day
n a pure SQL I use alias on column(query is valid and server return true result) but
Hibernate throw exception.
Also the problem is that the Hibernate retrieve wrong values for columns with the same
name.
--------------------------------------------------
Example 1:
SQL = SELECT
organizacije.id,
koda.vrednost AS k,
tip.vrednost AS t
FROM
organizacije
LEFT JOIN
sif_kodorg AS koda
ON koda.id=organizacije.koda
LEFT JOIN
sif_tiporg AS tip
ON tip.id=organizacije.tip_org
WHERE
organizacije.id=64
EntityManager.createNativeQuery(SQL) // error
error: org.hibernate.exception.SQLGrammarException: could not execute query
------------------------------------------
Example 2:
SQL = SELECT
organizacije.id,
koda.vrednost,
tip.vrednost
FROM
organizacije
LEFT JOIN
sif_kodorg AS koda
ON koda.id=organizacije.koda
LEFT JOIN
sif_tiporg AS tip
ON tip.id=organizacije.tip_org
WHERE
organizacije.id=64
When retrieving result in a array I get the same value for both columns koda.vrednost,
tip.vrednost
-----------------------------------
Why is here involved Hibernate Grammar if it's just a pure SQL, so is there any
solutions how to retrieve values of columns with same name?
Regards, Tomaž
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira