0

I have an existing db that I cannot alter. There are two tables, one (A) with a PK and one (B) with a FK pointing to the PK of the first. The respective columns are named (A).page_id and (B).cl_from. In Hibernate mapping i can set an id for the first, mapping the PK. I can also set a bag for the one-to-many relationship. For the second, I don't need an id, but a many-to-one relationship. How can you set a many-to-one relationship without an id? I don't want to insert an id to the class.. I've tried to set a composite key but had no luck..

// The PK class
<class name="Words" table="PAGE">
  <id name="id" column="PAGE_ID" />
  <property name="text" column="PAGE_TITLE" />  
  <bag cascade="all-delete-orphan" inverse="true" lazy="false" name="wordPages">
     <key column="PAGE_ID"/>
     <one-to-many class="CategoryItems"/>
  </bag>
</class>

// The FK class
<class name="CategoryItems" table="CATEGORYLINKS" >
  <composite-id> 
    <key-many-to-one name="id" column="CL_FROM" />
  </composite-id>
  <property name="text" column="CL_TO" />
</class>

And my classes:

 public class Words {

 private Long id;
 private String text;
 private ArrayList wordPages;
// getters - setters

public class CategoryItems implements Serializable  {

/**
 * 
 */
  private static final long serialVersionUID = 1L;
  private Long id;
  private String text;

//getters-setters

The latest error i get is: An association from the table CATEGORYLINKS refers to an unmapped class: java.lang.Long

1 Answer 1

1

should help with the following code:

public class CategoryItems implements Serializable  
{
  private static final long serialVersionUID = 1L;
  private Words id;
  private String text;

  //getters-setters
}
Sign up to request clarification or add additional context in comments.

1 Comment

It resolved the current error but now it's Path expected for join! [from Words as W inner join CategoryItems as I where I.text = 'myText']. This also occurred before but I haven't managed to solve with numerous ways..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.