Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate: get interface, rather than implementation

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a object hierarchy that includes both inheritance and and interface implementation. In certain cases, it makes sense for our object model to return an interface, rather than an implementation. However, when we attempt to retrieve, we don't get back any rows (empty resultset). What we see in the generated SQL is that hibernate appends a "1=2" to what would be an otherwise valid SQL query.

Has anyone else run into this before, or can you point me to examples of retrieval via interface? (E.g., getInterfaceA, rather than getClassA.)
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do you retrieve "the interface" ? can you show us some code

since an interface can not be instantiated you can not persist it. you can only get back an object that implements the given interface.

if you've mapped the interfaces and implementation (as an inheritance hierarchy) then you can get back implementations of a given interface trough Criteria or HGL. e.g.


i think best would be if you show some code and the mapping.

and i've never seen hibernate append "where 1 = 2" does not make much sense...

pascal
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic