-->
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.  [ 9 posts ] 
Author Message
 Post subject: Many-to-one mapping problem
PostPosted: Mon Jul 19, 2004 9:56 am 
Newbie

Joined: Thu Jul 15, 2004 3:21 am
Posts: 18
Location: Hamburg, Germany
Hi!
I use long-Datatypes for IDs. Inserting Mitspieler doesn't make a problem, but inserting a Tippgemeinschaft does:
No persister for: java.lang.Long
A Mitspieler(Player) can have several Teams (Tippgemeinschaft) to manage and a Team must have an admin.
Is my relation-mapping wrong?
Hier is my mapping file:
Code:
<class name="tippspiel.Mitspieler" table="MITSPIELER">

       <id name="id" type="long" 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>
   


Lena


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 10:00 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
change
Quote:
<id name="id" type="long" unsaved-value="null">
<column name="ID" sql-type="bigint(20)" not-null="true"/>
<generator class="native"/>
</id>


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


long is not Long ....

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 10:06 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
<id name="id" type="long" unsaved-value="null">


long cannot be null, Long can... show your pojo

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 10:11 am 
Newbie

Joined: Thu Jul 15, 2004 3:21 am
Posts: 18
Location: Hamburg, Germany
What does pojo mean?
Lena


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 10:16 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
oups, show javaBean

i mean if you have in your bean

private Long id; (typically unsaved-value = null)

it is not the same as
private long id; (typically unsaved-value = 0)

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 10:34 am 
Newbie

Joined: Thu Jul 15, 2004 3:21 am
Posts: 18
Location: Hamburg, Germany
I tried to insert an new Mitspieler:
Code:
Transaction tx = session.beginTransaction();

         Mitspieler tom = new Mitspieler();
         tom.setName("Banny");
         tom.setEmail("banny@gmx.de");
         tom.setPasswort("secret^2!");

         session.save(tom);
         tx.commit();


My DB got "Banny" and I've got this:
identifier of an instance of tippspiel.Mitspieler altered from 16 to 0
And hier are my pojos :) :

Code:
public class Mitspieler {
   private int id;
   private String name;
   private String email;
   private String passwort;
   private Set adminTippgemeinschaften;
   ...}

public class Tippgemeinschaft {
   private int id;
   private String name;
   private int adminId;
                ...}


Lena


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 10:35 am 
Newbie

Joined: Thu Jul 15, 2004 3:21 am
Posts: 18
Location: Hamburg, Germany
Oh sorry! I changed long to int to test!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 10:41 am 
Newbie

Joined: Thu Jul 15, 2004 3:21 am
Posts: 18
Location: Hamburg, Germany
I have too much disorder in my code... Some methods were with int-Datatypes. Sorry. Last error does not occur anymore.
Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 10:45 am 
Newbie

Joined: Thu Jul 15, 2004 3:21 am
Posts: 18
Location: Hamburg, Germany
So. I updated my classes. And here I am again with:
No persister for: java.lang.Long
tom is a Mitspieler.
Code:
Transaction tx3 = session.beginTransaction();
         
                  Tippgemeinschaft hsv = new Tippgemeinschaft();
                  hsv.setName("HSV Fanclub");
                  hsv.setAdminId(tom.getId());
                     session.save(hsv);
                                    tx3.commit();

Lena


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.