-->
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: many to many error
PostPosted: Sun Nov 21, 2004 6:02 pm 
Newbie

Joined: Wed Aug 25, 2004 11:53 am
Posts: 3
I am having difficulty getting my many-to-many mapping working. Here is me code and error:

Hibernate version: 2.1

Mapping document: Ahtlete
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
   <class
      name="ca.spintechnologies.runningmap.Athlete"
      table = "ATHLETE">
      <id
         name="id"
         column="id"
         type="integer">
            <generator class="increment"/>
      </id>
      <property name="email" column="email"/>
      <property name="userPassword" column="userpassword"/>
      <property name="userLevel" column="userlevel"/>
      <property name="userName" column="username"/>
      <property name="firstName" column="firstname"/>
      <property name="lastName" column="lastname"/>
      <property name="isActive" column="isactive"/>
      <property name="creationDate" column="creationdate"/>
      <idbag name="routes"
             table = "athlete_route"
             lazy = "true"
             cascade = "save-update">
             <collection-id type="integer" column="id">
                <generator class="sequence"/>
             </collection-id>
             <key column="athlete_id"/>
             <many-to-many class="ca.spintechnologies.runningmap.Route" column="route_id"/>
      </idbag>
   </class>
</hibernate-mapping>


Mapping document: Route
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
   <class
      name="ca.spintechnologies.runningmap.Route"
      table = "ROUTE">
      <id
         name="id"
         column="id"
         type="integer">
            <generator class="increment"/>
      </id>
      <property name="name" column="name"/>
      <property name="distance" column="distance"/>
   </class>
</hibernate-mapping>






Code between sessionFactory.openSession() and session.close():
Code:
Session session = util.currentSession();
           Transaction tx= session.beginTransaction();
           Query  query = session.createQuery("from Athlete as athlete where athlete.userName like '" + myUserName +
"'");
           Iterator it = query.iterate();
           if (it.hasNext()){
               myAthlete = (Athlete)it.next();
               myPassword = myAthlete.getUserPassword();
           }
           else{
              message.append("message='username does not exist' ");
           }
           tx.commit();
           HibernateUtil.closeSession();   
        }catch(Exception e){
           message.append("message='" + e.toString()+ "' ");
           System.out.println("****RMDB_ValidateUser; caught exception: " + e.toString()); 
        }   




Full stack trace of any exception that occurs:

    caught exception: net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of ca.spintechnologies.runningmap.Athlete.setRoutes

Name and version of the database you are using:

postgresql 7.4

The generated SQL (show_sql=true):
[list=]select athlete0_.id as id0_, athlete0_.email as email0_, athlete0_.userpassword as userpass3_0_, athlete0_.userlevel as userlevel0_, athlete0_.username as username0_, athlete0_.firstname as firstname0_, athlete0_.lastname as lastname0_, athlete0_.isactive as isactive0_, athlete0_.creationdate as creation9_0_ from ATHLETE athlete0_ where athlete0_.id=?
****RMDB_ValidateUser; caught exception: net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of ca.spintechnologies.runningmap.Athlete.setRoutes[/list]

Athlete POJO

Code:
package ca.spintechnologies.runningmap;
import java.util.HashSet;
import java.util.Set;
import java.util.Date;

public class Athlete{
   private int id;
   private String email;
   private String userPassword;
   private String userLevel;
   private String userName;
   private String firstName;
   private String lastName;
   private Date creationDate;
   private boolean isActive;
   
   private Set cities = new HashSet();
   private Set routes = new HashSet();
   private Set results = new HashSet();
 
   public Athlete(){}
   
 
   public int getId(){
      return id;
   }
   public void setId(int myId){
      this.id = myId;
   }
   //
   public boolean getIsActive(){
        return isActive;
   }
   public void setIsActive(boolean myBool){
        this.isActive = myBool;
   }
   //
   public Date getCreationDate(){
        return creationDate;
   }
   public void setCreationDate(Date myDate){
        this.creationDate = myDate;
   }
   //
   public String getEmail(){
      return email;
   }
   public void setEmail(String myEmail){
      this.email = myEmail;
   }
   //
   public String getUserPassword(){
      return userPassword;
   }
   public void setUserPassword(String myPassword){
      this.userPassword = myPassword;
   }
   //
   public String getUserLevel(){
      return userLevel;
   }
   public void setUserLevel(String myLevel){
      this.userLevel = myLevel;
   }
   
   public String getUserName(){
      return userName;
   }
   public void setUserName(String myUserName){
      this.userName = myUserName;
   }

   public String getFirstName(){
      return firstName;
   }
   public void setFirstName(String myFirstName){
      this.firstName = myFirstName;
   }

   public String getLastName(){
      return lastName;
   }
   public void setLastName(String myLastName){
      this.lastName = myLastName;
   }
   
   public Set getCities(){
      return this.cities;
   }
   public boolean removeCity(City myCity){
         if(this.cities.contains(myCity)){
              this.cities.remove(myCity);
              return true;
         }
         else{
              return false;
         }
   }
   public void addCity(City myCity){
         this.cities.add(myCity);
   }
   
   
   
   public Set getRoutes(){
      return this.routes;
   }
   public void setRoutes(Set myRouteSet){
       if(myRouteSet != null){
          this.routes = myRouteSet;
       }
       else{
          System.out.println("***From Athlete: myRouteSet is null");
       }
         
   }
   public void addRoute(Route myRoute){
         this.routes.add(myRoute);
   }
   
   public Set getResults(){
         return this.results;
   }
   public void addResult(Result myResult){
         this.results.add(myResult);
   }
}


_________________
Randy Troppmann
Spin Technologies Inc.
www.spintechnologies.ca


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.