Win a copy of Spring in Action (5th edition) this week in the Spring 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Retrieving "DiscriminatorColumn" value when querying an object  RSS feed

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My class hierarchy looks like this.


This is very simple example for ClassPerHierarchy inheritance and I have set the DiscriminatorColumn and DiscriminatorValue. While doing the query, I also want to retrieve the value in discriminator column. But the value does not come straightforward. I tried by declaring a field "vehicleModel" in Vehicle class but this throws out "Duplicate column" exception.

Any idea how this can be done ?
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I also want to retrieve the value in discriminator column


Why? Its not a property of your object that should have any meaning beyond defining the type of object. What do you want to do with it?
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try making the mapping @Column insertable/updateable=false.

Otherwise, since you know the value for an class without selecting it, you can just define a getDiscriminator method that returns it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!