Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: get interface, rather than implementation

 
Tina Coleman
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • 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.)
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic