-->
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: Referencing table with combined key without using blob?
PostPosted: Fri Sep 12, 2008 10:15 am 
Beginner
Beginner

Joined: Thu Oct 04, 2007 12:22 pm
Posts: 48
Hello!

I have problems creating a special relationship between two tables. First, what I intend to use:

The first table Actvity classifies a thing someone can do. It identifies by three attributes applicationId, activityName, groupName.
The second table is a user-binded counter. So for each user there can be n-UserActivites, each one associated with and counting a special Activity.
Important is, that a userActivity uses as primary key the userId and the combined primary key of an Activity.

Beneath in my mapping you can see my first thought about how to map the classes. This means a UserActivity _has_ a reference to an Activity named 'activity'.
But in the current mapping an error raises up: Hibernate wants to know the length of the key. I searched and found the answer that the reference of the activity is stored as blob and the length shall limit the indexed bytes.

But storing the reference as a blob is not what I intend. There shall be foreign key references to the keys of an activity.

But the only syntax I find to express the relation leads to a named property in the format of the referenced class (=> blob).

So is it possible (and how) to map only the keys of an associated Activity without storing the whole activity as a blob?

Thanks in advance for each hint.

Hibernate version:
3.2.3
Mapping documents:
Code:
<hibernate-mapping default-lazy="false">

  <class name="Activity"
      table="Activity">

   <composite-id>
        <key-property name="applicationId"/>
        <key-property name="activityName"/>
        <key-property name="groupName"/>
   </composite-id>

   <property
            name="applicationId"
        column="applicationId"
        type="long"
        length="11"
        not-null="true"
        insert="false"
        update="false" />
       
   <property
            name="activityName"
        column="activityName"
        type="string"
        not-null="true"
        insert="false"
        update="false" />

   <property
            name="groupName"
        column="groupName"
        type="string"
        length="11"
        not-null="true"
        insert="false"
        update="false" />

   <property
            name="maxExecutions"
        column="maxExecutions"
        type="int"
        length="11"
        not-null="true" />

  </class>

</hibernate-mapping>


Code:
<hibernate-mapping default-lazy="false">

  <class name="ActivityCounter"
      table="ActivityCounter">

   <composite-id>
        <key-property name="userId"/>
        <key-property name="activity"/>
   </composite-id>

   <property
      name="userId"
        column="userId"
        type="long"
        length="11"
        not-null="true"
        insert="false"
        update="false" />

   <many-to-one
      name="activity"
        class="Activity"
        not-null="true"
        insert="false"
        update="false">
        <column name = "activityName" />
        <column name = "groupName" />
        <column name = "applicationId" />
    </many-to-one>

   <property
      name="count"
        column="count"
        type="int"
        not-null="true" />

  </class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:
MySQL 5
Code:


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.