-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: many-to-many mapping with non-primary key
PostPosted: Wed May 16, 2007 3:16 am 
Newbie

Joined: Wed May 16, 2007 12:49 am
Posts: 1
I would like to have a many-to-many association between Folder class and Resource class,
but not using primary key in Resource table. Unfortunatelly, I have encountered some problems, which i cannot cope with.
Would somebody kindly help me?

What I would like to do is to let Folder class has the set of Resource classes, and also let Resouce class has the set of Folder classes. The problem is that Volume class failed to have folder set, though Folder class was able to have volume set in its class.(The folderSet in Volume classes is always blank and any folder class did not get in, even though it is associated in Folder_Resource table)

Hibernate version:
3.0
Name and version of the database:
MySQL 5.0

The database shema is designed as following. Here, I don't want to use primary key in Resource with association, while it is possible to use primary key in Folder.(Assume that Resource table has legacy primary key and it should not be modified.) More concreatly speaking, at the Folder_Resource table, Resource is associated with the R_ID, which is not primary key of Resource table, while Folder is associated with f_id, which is corresponded with primary key of Folder table.

DB schema:
Code:
create table Folder
(
  F_ID VARCHAR(30) primary key not null,
  Parent_F_ID VARCHAR(30),
  Name VARCHAR(30)
);

create table Folder_Resource
(
  F_ID VARCHAR(30),
  R_ID VARCHAR(30)
);

create table Resource
(
  oldID VARCHAR(20) primary key not null,
  capacity INTEGER,
  R_ID VARCHAR(30)
);



Mapping documents:

Code:
<class name="Folder" table="FOLDER">

  <id name="f_id" column="f_id" type="java.lang.String" >
    <generator class="assigned" />
  </id>
   
  <property name="name" column="name" type="java.lang.String" />
  <property name="parent_id" column="parentID" type="java.lang.String" />
   
  <set name="resourceSet" table="Folder_Resource" inverse = "true" lazy="false">
    <key column = "f_id"/>
    <many-to-many class="Resource" property-ref="r_id">
       <column name="r_id" not-null="true"/>
    </many-to-many>
  </set>
         
</class>

<class name="Resource" table="RESOURCE">
  <id name="oldID" column="oldID" type="java.lang.String" >
    <generator class="assigned" />
  </id>

  <property name="capacity" column="capacity" type="java.lang.Integer" />
  <property name="r_id" column="R_ID" type="java.lang.String" />


  <set name="folderSet" table="Folder_Resource" inverse = "true" lazy="false">
    <key column = "r_id"/>
    <many-to-many class="Folder" column="f_id"/>
  </set>
</class>


The symptom of the problem.
By analyzing the Hibernate SQL with debug mode, it turned out that <key column = "r_id"/> is associated with oldID, the primary key of Resource table.

The measurement i have taken so far
* Add the attribute, property-ref="r_id", to the <key column = "r_id"/> in Resource class mapping
-> the NULL EXCEPTION ERROR has occured. the message was following

Exception in thread "main" java.lang.NullPointerException
at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1596)
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:608)

Your advise and help is highly appreciated. Thank you very much.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.