-->
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.  [ 4 posts ] 
Author Message
 Post subject: onetomany mapping problem
PostPosted: Mon Mar 10, 2008 8:58 am 
Newbie

Joined: Sat Mar 08, 2008 6:52 am
Posts: 4
Hi everyone
i will make the question straight: how can i make a OneToMany bidirectional mapping without this excepcion:
Code:
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: org.cnio.appform.entity.User.interviews[org.cnio.appform.entity.Interview]
   at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1033)
   at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:576)
   at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:517)
   at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
   at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1136)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:316)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
... 3 more

and without using the @CollectionOfElements annotation, which is not a JPA standard?

any idea, suggestion... will be very welcome and i'd appreciate, as i didnt find any solution.

Thanks in advance. Following, the configuration and the code

Hibernate version: is 3.2.6 and hibernate annotations 3.3.0

Mapping documents: done via annotations

Code between sessionFactory.openSession() and session.close():
Code:
User owner = (User)session.createCriteria(User.class).
                              add(Restrictions.eq("nickname", nickname)).uniqueResult();
         
         Interview myInt = new Interview (intName, intDesc, owner);
         session.save(myInt);


although this code never gets to run as the exception is thrown previously. The code of the problematic classes (User and Interview in my case, assuming one user has many interviews, user is the One side of the relationship):
Code:
@Entity
@Table (name="appuser")
@SequenceGenerator(name="UserSeq", sequenceName="appuser_iduser_seq")
//                            allocationSize=1, initialValue=1)
public class User {

@Id @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="UserSeq")
@Column (name="iduser")
   private Integer id;
   
@Column (name="name")
   private String name;
@Column (name="midname")
   private String midname;
@Column (name="lastname")
   private String lastname;
@Column (name="nickname")
   private String nickname;
@Column (name="passwd")
   private String passwd;

// this is to implement the 1-N relathioship between user and interview
@OneToMany (mappedBy="owner",targetEntity=Interview.class)
   private Set<Interview> interviews;
   
// link to the join table to implement the M-N relationship user-role
@OneToMany (mappedBy="user")
   private Set<UserRole> userRoles;


   public User () {
      name = "";
      midname = "";
      lastname = "";
      nickname = "";
      passwd = "";
      userRoles = new HashSet<UserRole> ();
      
      interviews = new HashSet<Interview> ();
   }

// ... various getter an setter methods
}


Code:
@Entity
@Table (name="interview")
@SequenceGenerator(name="InterviewSeq",
                            sequenceName="interview_idinterview_seq")
//                            allocationSize=1, initialValue=1)
public class Interview {
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="InterviewSeq")
@Column (name="idinterview")
   private Integer id;
   
@Column (name="name")
   private String name;
@Column (name="description")
   private String description;

@ManyToOne (targetEntity=User.class)
@JoinColumn(name="iduser")
   private User owner;


   public Interview () {
      name = "";
      description = "";
      owner = new User ();
   }
   
   
/**
* Build an interview with the owner, which is just an user
* @param anUser the owner of this interview
*/   
   public Interview (String name, String description, User anUser) {
// guarantee referential integrity      
      this.owner = anUser;
      
      this.name = name;
      this.description = description;
      
// important to make the relationship inverse      
      owner.getInterviews().add(this);
   }
//... varios getter and setter methods again

}

Name and version of the database you are using: Postgresql 8.1


Top
 Profile  
 
 Post subject: Mapping exceptions
PostPosted: Mon Mar 10, 2008 10:03 am 
Newbie

Joined: Wed Mar 05, 2008 11:26 am
Posts: 8
I had a similar problem, and the solution was simply to ensure that both of the entities were mapped in my session-factory within my hibernate.cfg.xml file.

Example:

Code:

<mapping class="com.domain.model.State"/>   



It may not be as simple as that, but this solved all of my mapping exceptions.

AJ


Top
 Profile  
 
 Post subject: Re: Mapping exceptions
PostPosted: Mon Mar 10, 2008 10:24 am 
Newbie

Joined: Sat Mar 08, 2008 6:52 am
Posts: 4
ajile81 wrote:
I had a similar problem, and the solution was simply to ensure that both of the entities were mapped in my session-factory within my hibernate.cfg.xml file.


yeahhhhhhhh, thank you mate!!!! that was the problem and, as we dont work so often with that config file, i simply forgot to add the new class to it. without this support, i could be looking for the error for ages.

cheers again.

w i l l y


Top
 Profile  
 
 Post subject: Good to hear
PostPosted: Mon Mar 10, 2008 10:27 am 
Newbie

Joined: Wed Mar 05, 2008 11:26 am
Posts: 8
Glad I could help. Yes, that's one of the oft-overlooked items for me as well, and that's now on my "punch list" every time I add a new table entity.

Regards,

AJ


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