-->
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: Still many-to-one Problem help!!!
PostPosted: Mon Jul 19, 2004 11:46 am 
Newbie

Joined: Thu Jul 15, 2004 3:21 am
Posts: 18
Location: Hamburg, Germany
Hi!
Inserting Mitspieler doesn't make a problem, but inserting a Tippgemeinschaft still does:
No persister for: java.lang.Long
A Mitspieler(Player) can have several Teams (Tippgemeinschaft) to manage and a Team must have an admin.

Hier is my mapping file:
Code:
<class name="tippspiel.Mitspieler" table="MITSPIELER">

       <id name="id" unsaved-value="null">
         <column name="ID" sql-type="bigint(20)" not-null="true"/>
         <generator class="native"/>
      </id>

             
       <set name="adminTippgemeinschaften" inverse="true" lazy="true" cascade="all-delete-orphan">
           
            <key column="ADMIN_ID"/>
            <one-to-many class="tippspiel.Tippgemeinschaft"/>
         </set> </class>


<class name="tippspiel.Tippgemeinschaft" table="TIPPGEMEINSCHAFT">
      <id name="id" type="long" unsaved-value="null">
         <column name="ID" sql-type="bigint(20)" not-null="true"/>
         <generator class="native"/>
      </id>
       
       
      <many-to-one name= "adminId" class = "tippspiel.Mitspieler" column="ADMIN_ID" not-null="true" unique="true"/>        </class>


Here are my Beans:

Code:
public class Mitspieler {
   private long id;
   private String name;
   private String email;
   private String passwort;
...}
public class Tippgemeinschaft {
   private long id;
   private String name;
   private long adminId;
...}

And this is how I try to insert Tippgemeinschaft:
Code:
Transaction tx = session.beginTransaction();

         Mitspieler tom = new Mitspieler();
         tom.setName("Benny");
         tom.setEmail("benny@gmx.de");
         tom.setPasswort("secret^4!");
         
         session.save(tom);
         tx.commit();
//Get Benny's Id = adminId (and cast it to long) ...
         
         Transaction tx3 = session.beginTransaction();

// I want Benny to admin this Team(Tippgemeinschaft):

         Tippgemeinschaft hsv = new Tippgemeinschaft();
         hsv.setName("HSV Fanclub");
         hsv.setAdminId(adminId);
         session.save(hsv);
         tx3.commit();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 2:12 pm 
Regular
Regular

Joined: Tue Oct 28, 2003 8:25 am
Posts: 72
Location: Belgium
First, something looks strange:

you have defined your primary keys as primitive "long" in your bean classes but you set the unsaved value to "null" in the xml mapping. I'm not sure how Hibernate handles this but you should change the types to java.lang.Long or use for example "0" as unsaved value.

But the real problem is something else. Looks like you haven't completely understood how the many-to-one mapping is working. Have a closer look at chapter 6.8 of the manual.

In fact, you should change

Code:
private long adminId;


in the Tippgemeinschaft class for this:

Code:
private Mitspieler admin;


and change the getter/setter accordingly.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 3:38 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
lesha,
please don't crosspost
http://forum.hibernate.org/viewtopic.php?t=932718

you have to know about java types....

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 4:25 am 
Newbie

Joined: Thu Jul 15, 2004 3:21 am
Posts: 18
Location: Hamburg, Germany
IT WORKS!!!
Thanks a lot!

Lena

P.S.Sorry for crossposting (never used a Forum before). But I learn fast ;)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 4:26 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
no pb but don't do it again ;)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 12:44 am 
Newbie

Joined: Fri Jul 23, 2004 12:13 am
Posts: 7
Hello, I encountered the same problem but after reading section 6.8 in the docs and this post I am still missing something.

I have basically the thing:

public class Mitspieler {
private long id;
private String name;
private String email;
private String passwort;
...}
public class Tippgemeinschaft {
private long id;
private String name;
private Mitspieler admin;
...}

Mitspieler tom = new Mitspieler();
tom.setName("Benny");
tom.setEmail("benny@gmx.de");
tom.setPasswort("secret^4!");
session.save(tom);
tx.commit();

Tippgemeinschaft hsv = new Tippgemeinschaft();
hsv.setName("HSV Fanclub");
hsv.setAdmin(tom);
session.save(hsv);
tx.commit();


session.save(hsv); always throws the exception -> No persister for: java.lang.Integer
All columns long.
What else could be the cause of this?


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.