-->
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.  [ 6 posts ] 
Author Message
 Post subject: Many-to-One with unique=true understanding problem
PostPosted: Thu Nov 03, 2005 4:34 am 
Newbie

Joined: Thu Nov 03, 2005 4:19 am
Posts: 3
Hi all,
i guess i have a understanding problem with hibernate. I read a lot of doc's yesterday evening but i can't get it. I have a quite simple problem.
My class MemberSongs has a getter/setter named "musicfile". The field is of type "kasong". In each MemberSong must be a filled "musicfile".
MemberSong is connected with "song_id" to "kasong" with the field "id".

This is, what my mapping looks like:
[/code]
<class name="KAMembersSongs" table="ka_members_songs">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="songId" column="song_id"/>
<property name="musicfile" type="KARealaudio"/>
<many-to-one name="musicfile"
class="de.possessed.zipcreator.KARealaudio"
unique="true"
column="id"
not-null="true"/>
</class>

<class name="KARealaudio" table="ka_realaudio">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="dateiBuy" column="datei_buy" />
</class>
[/code]

I would expect that i get this link, but following error occures. Could you explain me where my mistake is? i guess it's a small problem.

Regards,
Chris

Hibernate version: 3.x
Full stack trace of any exception that occurs:
Caused by: org.hibernate.MappingException: Could not determine type for: de.possessed.zipcreator.KARealaudio, for columns: [org.hibernate.mapping.Column(musicfile)]

Name and version of the database you are using:
MySQL4.1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 4:43 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
KAMemberSongs should have a set of KARealaudio

the many-to-one should be in KARealAudio pointing to KAMemberSongs, the property musicfile in KAMemberSongs is not needed if there is a 1 to many relationshiup between KAMemberSongs and KARealaudio.


Read thourgh more of the mapping examples on mapping collections.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 4:49 am 
Newbie

Joined: Thu Nov 03, 2005 4:19 am
Posts: 3
hi jamie,

it is a 1 to 1 relation. IN the documentation is written that i need the "many-to-one" tag with option unique=true. I don't need a Set- i need a single object. Isn't this possible?

Regards and thanks,
chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 4:56 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Could you find that bit in the documentation?

Also if it really is just a 1 - 1, which makes no sense from your class name.

KAMemberSongs implies it contains multiple songs. But this could be a misunderstanding over what your are attempting to do.


Top
 Profile  
 
 Post subject: Re: Many-to-One with unique=true understanding problem
PostPosted: Thu Nov 03, 2005 4:59 am 
Regular
Regular

Joined: Thu Oct 27, 2005 8:06 am
Posts: 55
Location: München, Germany
Cy23 wrote:
<property name="musicfile" type="KARealaudio"/>


This line is superfluous. You declare the musicfile variable already in your many-to-one, one line later. In this line, you suggest that KARealaudio is a user-defined type, without properly defining it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 7:56 am 
Newbie

Joined: Thu Nov 03, 2005 4:19 am
Posts: 3
First, thank you.

Jamie you are right, the classnames are not good. But this is not my system. I just wanted to demonstrate that it is a good idea to use hibernate for such a "system". I hope i'll enlightend to prove that statement :)

Let me clarify:
In my class
KAMemberSongs.musicfile
shall a
KARealaudio be stored.

Every KAMemberSongs-Instance has exactly one KARealaudio-Instance in the field musicfile. The tupels are linked with: KAMemberSongs.song_id -> KARealaudio.id

Wuah, in the moment i wrote this and thought about your hints, i got it!!
Its just easy!
Here is my correct definition:

Code:
<class name="KAMembersSongs" table="ka_members_songs">
      <id name="id" column="id">
         <generator class="native"/>
      </id>
<!-- THIS MUST BE COMMENTED OUT -->
      <!-- property name="songId" column="song_id"/ -->
      <many-to-one name="musicfile"
                class="KARealaudio"
                unique="true"
                column="song_id"
                not-null="true"/>
   </class>

<class name="KARealaudio" table="ka_realaudio">
      <id name="id" column="id">
         <!-- generator class="native"/ -->
         <generator class="native"/>
      </id>
      <property name="dateiBuy" column="datei_buy" />
   </class>


I really had to delete the son_id definition. I hope i will get i through a setter anyway.

Well, thank you very much! Hope this thread will help others.
CHeers
Chris


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

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.