Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: mappedBy reference an unknown target entity property
PostPosted: Thu Jul 03, 2008 9:24 am 
Newbie

Joined: Thu Jun 26, 2008 9:36 am
Posts: 10
Hi, I have a problem with my code and don't understand where is the problem.


I want to use this for a database of 3 tables :

Code:
CREATE TABLE  `algorithmen` (
  `Id` int(11) NOT NULL auto_increment,
  `Name` varchar(20) default NULL,
  PRIMARY KEY  (`Id`)
)

CREATE TABLE  `attribute` (
  `Id` int(11) NOT NULL auto_increment,
  `Name` varchar(20) default NULL,
  `Unit` varchar(20) default NULL,
  PRIMARY KEY  (`Id`)
)


CREATE TABLE  `algoattribute` (
  `IdAttribute` int(11) NOT NULL default '0',
  `IdAlgorithmen` int(11) NOT NULL default '0',
  `OrdnungIndex` int(11) default NULL,
  PRIMARY KEY  (`IdAttribute`,`IdAlgorithmen`),
  CONSTRAINT `algoattribute_ibfk_1` FOREIGN KEY (`IdAttribute`) REFERENCES `attribute` (`Id`),
  CONSTRAINT `algoattribute_ibfk_2` FOREIGN KEY (`IdAlgorithmen`) REFERENCES `algorithmen` (`Id`)
)




Here is my code :

For the table "Attribut" :
Code:
@Entity
@Table(name = "attribute", catalog = "algoattribut")
@SuppressWarnings("serial")
public class Attribute implements Serializable {

   /**
    * Attribute id.
    */
   private Integer id;
   
   /**
    * Attribute name.
    */
   private String name;
   
   /**
    * Attribute unit.
    */
   private String unit;
   
   /**
    * List of Algoattribute
    */
   private List<Algoattribute> algoattributes = null;

   
   /**
    * <p>
    * </p>
    * @return id
    */
   @Basic
   @Id
   @GeneratedValue
   @Column(name = "Id")
      public Integer getId() {
      return id;
   }

   /**
    * @param id new value for id
    */
   public void setId(Integer id) {
      this.id = id;
   }
   
   /**
    * @return name
    */
   @Basic
   @Column(name = "Name", length = 20)
      public String getName() {
      return name;
   }

   /**
    * @param name new value for name
    */
   public void setName(String name) {
      this.name = name;
   }
   
   /**
    * @return unit
    */
   @Basic
   @Column(name = "Unit", length = 20)
      public String getUnit() {
      return unit;
   }

   /**
    * @param unit new value for unit
    */
   public void setUnit(String unit) {
      this.unit = unit;
   }
   
   /**
    * Get the list of Algoattribute
    */
   [b] @OneToMany(mappedBy="attribute")[/b]
    public List<Algoattribute> getAlgoattributes() {
       return this.algoattributes;
    }
   
   /**
    * Set the list of Algoattribute
    */
    public void setAlgoattributes(List<Algoattribute> algoattributes) {
       this.algoattributes = algoattributes;
    }


}


The code for the class Algorithmen is very similar, and this is the code for the class AlgoAttribut :



Code:
@Entity
@Table(name = "algoattribute", catalog = "algoattribut")
@SuppressWarnings("serial")
public class Algoattribute implements Serializable {

   /**
    * Primary key
    */
   private AlgoattributePK algoattributePK;

   /**
    * Attribute ordnungIndex.
    */
   private Integer ordnungIndex;
   
   
   /**
    * Get the primary key
    */
   @Basic
   @Id
   public AlgoattributePK getAlgoattributePK() {
      return this.algoattributePK;
   }
   
   /**
    * set the primary key
    */
   public void setAlgoattributePK(AlgoattributePK algoattributePK) {
      this.algoattributePK = algoattributePK;
   }


      

      
   /**
    * @return ordnungIndex
    */
   @Basic
   @Column(name = "OrdnungIndex")
      public Integer getOrdnungIndex() {
      return ordnungIndex;
   }

   /**
    * @param ordnungIndex new value for ordnungIndex
    */
   public void setOrdnungIndex(Integer ordnungIndex) {
      this.ordnungIndex = ordnungIndex;
   }
   

   /**
          *
     */
   @SuppressWarnings("serial")
   @Embeddable
   public static class AlgoattributePK implements Serializable {

      /**
       * Attribute attribute
       */
       private Attribute attribute;   


      /**
       * Attribute algorithmen
       */
       private Algorithmen algorithmen;   


   /**
    * get attribute
    */
         [b]@ManyToOne
         @JoinColumn(name = "IdAttribute")[/b]
         public Attribute getAttribute() {
            return this.attribute;
         }
         
         /**
          * set attribute
          */
         public void setAttribute(Attribute attribute) {
            this.attribute = attribute;
         }      
   /**
    * get algorithmen
    */
         [b]@ManyToOne
         @JoinColumn(name = "IdAlgorithmen")[/b]
         public Algorithmen getAlgorithmen() {
            return this.algorithmen;
         }
         
         /**
          * set algorithmen
          */
         public void setAlgorithmen(Algorithmen algorithmen) {
            this.algorithmen = algorithmen;
         }      

      /**
       * calculate hashcode
       */
      @Override
      public int hashCode()
      {
         //TODO : implement this method
         return super.hashCode();
      }

      /**
       * equals method
       */
      @Override
      public boolean equals(Object object)
      {
         //TODO : implement this method
         return super.equals(object);
      }

   }

}



And I have this problem :
Quote:
Exception in thread "main" java.lang.ExceptionInInitializerError
at pack.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:22)
at Test.main(Test.java:16)
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: pack.pojo.Algoattribute.algorithmen in pack.pojo.Algorithmen.algoattributes



And I don't find out from where the problem comes from...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 8:17 am 
Newbie

Joined: Thu Jun 26, 2008 9:36 am
Posts: 10
I forgot to say that this code has been generated with the plugin Salto-db.

Does anyone see where is the problem ?

I don't know how to map the attribut of the inner class.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 9:05 am 
Newbie

Joined: Thu Jun 26, 2008 9:36 am
Posts: 10
I found something if it can help someone :

Instead of :
Code:
@OneToMany(mappedBy="attribute")
    public List<Algoattribute> getAlgoattributes() {
       return this.algoattributes;
    }


I wrote :
Code:
@OneToMany
    @JoinColumn(name="IdAttribute")
    public List<Algoattribute> getAlgoattributes() {
       return this.algoattributes;
    }


And it seems to work ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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.