-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with @ManyToOne/@OneToMany
PostPosted: Fri Jun 17, 2011 8:39 am 
Newbie

Joined: Fri Jun 17, 2011 8:18 am
Posts: 2
Hi @all,
i've a problem with hibernate and a @ManyToOne/@OneToMany-relation and don't know how solve it. The following Exception occures and I don't know why:
Exception in thread "main" org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: de.hfu.wi.aam.sa.calendar.persistence.entities.CalendarUser.lstTasks[de.hfu.wi.aam.sa.calendar.persistence.entities.Task]

The message only occures for the relation between the class Task and CalenderUser although I've completely identical annotations to the other Classes, which are working.
Without this particular relation of Tasks and CalenderUsers everything is working, also the other relations as you can see in the two classes.
The classes are also mapped by my hibernate.config.xml file.

Is there anybody who can help me or has a hint for me?

Code:
package de.hfu.wi.aam.sa.calendar.persistence.entities;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.JoinColumn;

@Entity
public class CalendarUser {

   @Id
   private String id;
   private int firstname;
   private int lastName;
   
   @OneToMany(targetEntity = UserAppointment.class, mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
   private List<UserAppointment> appointments;
   
   @OneToMany(targetEntity = Task.class, mappedBy = "calendarUserOwner", cascade = CascadeType.ALL, fetch=FetchType.LAZY)
   private List<Task> lstTasks;
   
//   @OneToMany(targetEntity = Task.class, mappedBy = "owner", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
//   private List<Task> tasks;
   
   @OneToMany(targetEntity = Appointment.class, mappedBy = "creator", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
   private List<Appointment> createdAppointments;
   
   //TODO Gruppenfunktionalität gehört wohl eher ins UserMgmt
   @ManyToMany
   @JoinTable(name="JOIN_USER_GROUP",
         joinColumns={@JoinColumn(name="CALENDER_USER_ID")},
         inverseJoinColumns={@JoinColumn(name="USER_APPOINTMENT_ID")})
   private List<Group> groups;

   public CalendarUser(String id, int firstname, int lastName,
         List<UserAppointment> userAppointments, List<Task> tasks,
         List<Appointment> createdAppointments, List<Group> groups) {
      super();
      this.id = id;
      this.firstname = firstname;
      this.lastName = lastName;
      this.appointments = userAppointments;
//      this.tasks = tasks;
      this.createdAppointments = createdAppointments;
      this.groups = groups;
   }

   public String getId() {
      return id;
   }

   public int getFirstname() {
      return firstname;
   }

   public int getLastName() {
      return lastName;
   }

   public List<UserAppointment> getAppointments() {
      return appointments;
   }

   public List<Appointment> getCreatedAppointments() {
      return createdAppointments;
   }

   public List<Group> getGroups() {
      return groups;
   }
   
   public void setId(String id) {
      this.id = id;
   }

   public void setFirstname(int firstname) {
      this.firstname = firstname;
   }

   public void setLastName(int lastName) {
      this.lastName = lastName;
   }

   public void setAppointments(List<UserAppointment> appointments) {
      this.appointments = appointments;
   }

   public void setCreatedAppointments(List<Appointment> createdAppointments) {
      this.createdAppointments = createdAppointments;
   }
   
   public void setGroups(List<Group> groups) {
      this.groups = groups;
   }

}


Code:
package de.hfu.wi.aam.sa.calendar.persistence.entities;

import java.util.Date;

import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

public class Task extends Event {

   @Temporal(TemporalType.TIMESTAMP)
   private Date due;

//   @ManyToOne //@JoinColumn(name = "USER_FK")
//   private CalendarUser owner;
   
   @ManyToOne @JoinColumn(name = "FK_calendarUserOwner")
   private CalendarUser calendarUserOwner;

   @ManyToOne
   @JoinColumn(name = "CATEGORY_FK")
   private Category category;

   public Task(String title, String description, Date due, CalendarUser owner,
         Category category) {
      super(title, description);
      this.due = due;
      //this.owner = owner;
      this.category=category;
   }

   public Date getDue() {
      return due;
   }

   public Category getCategory() {
      return category;
   }

   public void setDue(Date due) {
      this.due = due;
   }

//   public CalendarUser getOwner() {
//      return owner;
//   }

//   public void setOwner(CalendarUser owner) {
//      this.owner = owner;
//   }

   public void setCategory(Category category) {
      this.category = category;
   }
}


Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

   <session-factory>

      <!-- Database connection settings -->
      <property name="connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
      <property name="connection.url">jdbc:derby://localhost:1527/HibernateDb;create=true</property>
      <property name="connection.username">user</property>
      <property name="connection.password">password</property>
      <property name="hibernate.default_schema">CALENDERTOOL</property>

      <!-- JDBC connection pool (use the built-in) -->
      <property name="connection.pool_size">2</property>

      <!-- SQL dialect -->
      <property name="dialect">org.hibernate.dialect.DerbyDialect</property>

      <!-- Enable Hibernate's current session context -->
<!--       Standardwert war hier "thread". Wird allerdings für besseres Sessionhandling (bzw.) eigenes geändert -->
      <property name="current_session_context_class">thread</property>

      <!-- Disable the second-level cache -->
      <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

      <!-- Echo all executed SQL to stdout -->
      <property name="show_sql">true</property>
      
      <mapping class="de.hfu.wi.aam.sa.calendar.persistence.entities.Task"/>
      <mapping class="de.hfu.wi.aam.sa.calendar.persistence.entities.Appointment"/>
      <mapping class="de.hfu.wi.aam.sa.calendar.persistence.entities.CalendarUser"/>
      <mapping class="de.hfu.wi.aam.sa.calendar.persistence.entities.Category"/>
      <mapping class="de.hfu.wi.aam.sa.calendar.persistence.entities.Event"/>
      <mapping class="de.hfu.wi.aam.sa.calendar.persistence.entities.Group"/>      
      <mapping class="de.hfu.wi.aam.sa.calendar.persistence.entities.UserAppointment"/>
      
      <!-- Drop and re-create the database schema on startup <property name="hbm2ddl.auto">create</property>
         <mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/> <mapping
         resource="org/hibernate/tutorial/domain/Person.hbm.xml"/> -->
   </session-factory>

</hibernate-configuration>



Top
 Profile  
 
 Post subject: Re: Problem with @ManyToOne/@OneToMany
PostPosted: Fri Jun 17, 2011 8:57 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You have no @Entity annotation on the Task class.


Top
 Profile  
 
 Post subject: Re: Problem with @ManyToOne/@OneToMany
PostPosted: Fri Jun 17, 2011 9:09 am 
Newbie

Joined: Fri Jun 17, 2011 8:18 am
Posts: 2
OOOH GOD.
HOW STUPID HAVE I BEEN!!!
(What a stupid trivial mistake!!!).
GREAT THX.

Sry, for asking such a easy question.
Did a lot of stuff, but actually forgot exactly that; to check the Entity.

Well..now it works.
thx.


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