Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inserting data using HQL on multiple tables.  RSS feed

Patrick Fong
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I want to construct a Hibernate object that refers to two database tables. I have one object called Attribute and another called Activity. The object Attribute is read only, and has a Many-to-Many relationship with Activity. The following is the definition of Attribute

Here is the Activity hbm.xml file

My questions are
  • How do you (using HQL) insert AND delete a single value into the relationship table (one attribute ID, one activity ID)?

  • UPDATE: Considering the fact that HQL inserts only support inserts from another table, how do you reference the foreign keys in the relationship table (that is the attribute and activity identities) in HQL?
    Here is my attempt -

    Error message - Attribute.activities isn't map!

  • Can I use a java.util.Set in the Attribute object only as a place holder and not load data into it, because I rather load the relationship in a separate object?
  • Do I just use <sql-query> to load the other object by specifying the bean properties of the other object?

  • Thanks
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!