HQL is unable to understand a class's property which is a set of another class

Matin Kh

I am having two classes, say A and B.
A has a set of B as its property. B has no idea about A.

Class A {
    @OneToMany(fetch=FetchType.LAZY)
    @JoinTable(name = "A_B_MAPPING", joinColumns = @JoinColumn(name = "A_ID") , inverseJoinColumns = @JoinColumn(name = "B_ID"))
    private Set<B> bs;
}

The problem is, when I want to delete those records of A which do not have B, HQL does not understand it! My code is like this:

String hql = "DELETE FROM A WHERE bs IS NULL";
Query query = getSession().createQuery(hql);
query.executeUpdate(); // <-- Here an exception is thrown

As it seems, the HQL is unable to understand that this property is not a column, and it has to join to the A_B_MAPPING.
I have also noticed that the generated query is referring to this bs property
as non-qualified-property-ref!

So the question is, how can I modify my query to achieve my goal?

eternay

In HQL, you need to declare an alias to use it as your instance variable and access the fields. Try to modify your query like that:

String hql = "DELETE FROM A a WHERE a.bs IS NULL";

Another problem with HQL and collections is that maybe, the collection won't be null, but empty. In that case, you should use is empty instead of is null:

String hql = "DELETE FROM A a WHERE a.bs IS EMPTY";

I think you need the is empty query form to solve your problem.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Set value to a class object which is property of another class - Objective c

From Dev

Unable to to set the italic property of the font class

From Dev

accessing class property which is added by frord declaration from another class

From Dev

Unable to understand Class object

From Dev

KVO not working (observing another class's property)

From Dev

Can I use another class's property without extending that class?

From Dev

Use class as a property in another class

From Dev

selecting list of object using HQL when the object is a property of another entity class

From Dev

hibernate: Unable to locate appropriate constructor on class - HQL

From Dev

Set a class property to a class in VBA?

From Dev

Swift Class Property Of Another Property

From Dev

Arrayformula shows error: Unable to set the formulaarray property of the range class

From Dev

ASP.NET MVC Fluent Validation doesn't work on the client side for view model's property which is another type of class

From Dev

Checking if property is set in class

From Dev

Set Property in Static Class

From Dev

Objective-C Set Property from Another Class Returns Null

From Dev

Unable to set a TextBox text owned by MainWindow from another class

From Dev

accessing property from another viewController's class in Swift?

From Dev

using a class name in another class property.?

From Dev

Having another class as a static property on a class

From Dev

One class override the property of another class

From Dev

Referencing property of one class in another class?

From Dev

populating A Class that has another class as a property

From Dev

How to use class property in another class ?

From Dev

Accessing parent class property set by child class

From Dev

How to set the base class property of a generic class

From Dev

Set property of derived class on base class' instance

From Dev

Set property of a class in a destination controller

From Dev

How to set a view's outlets' values from within another class

Related Related

  1. 1

    Set value to a class object which is property of another class - Objective c

  2. 2

    Unable to to set the italic property of the font class

  3. 3

    accessing class property which is added by frord declaration from another class

  4. 4

    Unable to understand Class object

  5. 5

    KVO not working (observing another class's property)

  6. 6

    Can I use another class's property without extending that class?

  7. 7

    Use class as a property in another class

  8. 8

    selecting list of object using HQL when the object is a property of another entity class

  9. 9

    hibernate: Unable to locate appropriate constructor on class - HQL

  10. 10

    Set a class property to a class in VBA?

  11. 11

    Swift Class Property Of Another Property

  12. 12

    Arrayformula shows error: Unable to set the formulaarray property of the range class

  13. 13

    ASP.NET MVC Fluent Validation doesn't work on the client side for view model's property which is another type of class

  14. 14

    Checking if property is set in class

  15. 15

    Set Property in Static Class

  16. 16

    Objective-C Set Property from Another Class Returns Null

  17. 17

    Unable to set a TextBox text owned by MainWindow from another class

  18. 18

    accessing property from another viewController's class in Swift?

  19. 19

    using a class name in another class property.?

  20. 20

    Having another class as a static property on a class

  21. 21

    One class override the property of another class

  22. 22

    Referencing property of one class in another class?

  23. 23

    populating A Class that has another class as a property

  24. 24

    How to use class property in another class ?

  25. 25

    Accessing parent class property set by child class

  26. 26

    How to set the base class property of a generic class

  27. 27

    Set property of derived class on base class' instance

  28. 28

    Set property of a class in a destination controller

  29. 29

    How to set a view's outlets' values from within another class

HotTag

Archive