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: