Register / Login
Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of
Kotlin for Android App Development
this week in the
this forum made possible by our volunteer staff, including ...
Stephan van Hulst
Object Relational Mapping
Other Application Frameworks
Hibernate - native SQL query, get more than one Entity?
posted 2 months ago
Hi, I am using following code to execute native SQL query with hibernate:
Query zonesQuery = session.createNativeQuery( "Select * \n" + "FROM dbo.Structure AS S\n" + "JOIN dbo.StructureLocationType AS SLT ON SLT.StructureId = S.Id\n" + "WHERE SLT.LocationTypeId = :lc").addEntity(StructureEntity.class); zonesQuery.setParameter("lc", locationTypeID); List<StructureEntity> zones = zonesQuery.list();
So it works and it gets me list of StructureEntity
now, because my sql query "join" from StructureLocationType table, is there possibility to get whole row as well, still using single query?
Would be grateful for some help,
posted 2 months ago
I thin you have to add the second table to you from and add the id of the second table to where.
Query zonesQuery = session.createNativeQuery( "Select * \n" + "FROM dbo.Structure, dbo.StructureLocationType AS S\n" + "JOIN dbo.StructureLocationType AS SLT ON SLT.StructureId = S.Id\n" + "WHERE SLT.LocationTypeId = :lc").addEntity(StructureEntity.class); zonesQuery.setParameter("lc", locationTypeID); List<StructureEntity> zones = zonesQuery.list();
It's good to be able to use someting, it's better to understand how it works.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
Boost this thread!
Iterating a List Using JSTL
How to Parse Multitple Entities In Hibernate NativeSQL Returned List
Hibernate : QueryParameterException could not locate named parameter
Mixing direct SQL with HQL in the same transaction
unnecceary join with other entities