So to try to flesh it out a bit more... I have an object let's call User and I want to know if that user is an employee or not. Employee's are their own object. So what I want to do rather than have an employee object is to have a boolean that tells me whether or not that User is an employee. I think this could be done with some form of readonly join?
Asked
Active
Viewed 671 times
1
-
A read only join? What does your database look like? Can you change it? (I.e., could you just add a boolean column to the user table) – Vala Jul 24 '12 at 12:24
-
no... i just want a boolean for if a row exists... basically i'm making up a column/variable based on whether or not a row exists. I am just saying that i'd assume it would be a read only join – Nate Spector Jul 24 '12 at 12:26
-
Can http://stackoverflow.com/a/2986354/692560 help you out? (Hibernate specific). – Vala Jul 24 '12 at 12:35
3 Answers
1
You can use a @JoinColumn
to join the User
object to an Employee
object (you don't have to have more than the ID in it). You also don't need to have a getter for the Employee object, but you can now write an isEmployee()
method that does the check employee != null
. You probably want to make sure you use an eager fetch to always have the information there.

Vala
- 5,628
- 1
- 29
- 55
0
JPA has a count functionality you can use in JPQL. You just have to make the distinction if it's an employee or not in your where clause.

Kurt Du Bois
- 7,550
- 4
- 25
- 33
-
i dont want to use jpql. i want it to just be jpa annotations or one method – Nate Spector Jul 24 '12 at 13:02
0
You can annotate getter method with @Transient and inside this method write logical operation, like if user_type is EMP then return true

Ramanqul Buzaubak
- 493
- 4
- 14