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

Using the discriminator column in QL queries and primary keys

 
Danny Matthews
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm fairly new to EJB and am trying to put together my first application.

The issue I'm having it with the use of discriminator columns. Specifically, I can't figure out how to refer to them within QL queries and don't seem to be able to use them as part of a composite primary key.

I've pasted the query which is giving me issues below. The discriminator field is SENSOR_TYPE.



Any help on how these things can be achieved (if at all) would be greatly appreciated.

Cheers,

Danny

 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to query this in JPQL in JPA 1.0, but JPA 2.0 added a Type function.

i.e.
SELECT Type(d) FROM SensorData d

As for using the type as part of the primary key, this may be more difficult. You could try just mapping the type field and putting an @Id on it, that might work depending on your JPA provider. You may need to put insertable/updateable=false. If you are using EclipseLink this is possible, but requires using a customizer.
 
Danny Matthews
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, wonderful. Thank you. The use of Type seems to have worked fine.

Thanks for the advice about discriminator use within a primary key also. I haven't had a chance to look into that yet but I'll post up the results when I do.

Thanks again,

Danny
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic