Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud
this week in the
Cloud/Virtualization
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Paul Clapham
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Saloon Keepers:
Tim Holloway
Carey Brown
Roland Mueller
Piet Souris
Bartenders:
Forum:
Object Relational Mapping
Hibernate: native query to wrap the collection
Edward Chen
Ranch Hand
Posts: 798
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
In the hibernate, do we have a similar function like this
<collection name="orders" class="Order"> <sql-query> select * from orders ..... </squ-query> </collection>
Actually, just let native query to wrap the collection. Can we do this ?
Thanks.
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Sure, if you're asking if you can do a regular select, it's no problem. Here's a sample snippet:
final static String SELECT = "SELECT * FROM USER"; private static void hibernateNativeQueryFindAll(SessionFactory factory) { Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery sqlQuery = session.createSQLQuery("SELECT * FROM USER"); List results = sqlQuery.list(); for (int i = 0; i < results.size(); i++) { Object[] o = (Object[]) (results.get(i)); int id = (Integer) (o[0]); String name = (String) (o[1]); String password = (String) (o[2]); System.out.println(id + name + password); } session.getTransaction().commit(); }
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
how to save collection object into database
Id key in .hbm.xml
Hibernate collection mapping
How to pass a collection to 'IN' parameter in native query
Brain power pg 269 in Head First EJB
More...