-->
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.  [ 6 posts ] 
Author Message
 Post subject: Unmapped class exception when using proxy interfaces
PostPosted: Fri Aug 12, 2005 3:34 pm 
Beginner
Beginner

Joined: Mon Feb 23, 2004 5:11 pm
Posts: 39
Hibernate version:
Hibernate 3.0.5
Mapping documents:
Code:
<class name="FooImpl" proxy="Foo" table="FOO" >.......</class>


Code:
<class name="Bar" table="BAR">
   ...
   ...
   <many-to-one class="Foo" ......./>
   ...
   ...
</class>



Bar.java
Code:
private Foo foo;
public Foo getFoo() {
    return foo;
}

public void setFoo(Foo f) {
    foo = f;
}




When I try to use this, I get the following exception while initializing:

Caused by: org.hibernate.MappingException: An association from the table BAR refers to an unmapped class: Foo


What am i missing?


Top
 Profile  
 
 Post subject: Re: Unmapped class exception when using proxy interfaces
PostPosted: Fri Aug 12, 2005 4:10 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
bshaw wrote:
Hibernate version:
Hibernate 3.0.5
Mapping documents:
Code:
<class name="FooImpl" proxy="Foo" table="FOO" >.......</class>


Code:
<class name="Bar" table="BAR">
   ...
   ...
   <many-to-one class="Foo" ......./>
   ...
   ...
</class>



Bar.java
Code:
private Foo foo;
public Foo getFoo() {
    return foo;
}

public void setFoo(Foo f) {
    foo = f;
}




When I try to use this, I get the following exception while initializing:

Caused by: org.hibernate.MappingException: An association from the table BAR refers to an unmapped class: Foo


What am i missing?


You don't have a mapped class named "Foo" Only one named "FooImpl" Hibernate will use Foo for proxying but that doesn't change the name of the class associated with Hibernate.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 4:17 pm 
Beginner
Beginner

Joined: Mon Feb 23, 2004 5:11 pm
Posts: 39
I realize that I dont have the mapping file for the Foo. But I wasn't sure if I needed one. Foo is just a interface I am using for proxy. I dont remember reading anywhere in the docs that the proxy interfaces would have to be mapped as well.

I will give it a try anyways.....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 4:33 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
bshaw wrote:
I realize that I dont have the mapping file for the Foo. But I wasn't sure if I needed one. Foo is just a interface I am using for proxy. I dont remember reading anywhere in the docs that the proxy interfaces would have to be mapped as well.

I will give it a try anyways.....


I don't think you need to map it. Just refer to FooImpl and Hibernate will use Foo when creating the LazyInitialization Proxy.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 5:02 pm 
Beginner
Beginner

Joined: Mon Feb 23, 2004 5:11 pm
Posts: 39
I am not sure what you mean exactly when you say "refer to FooImpl". But I already tried using FooImpl (instead of Foo) in Bar.java , but I get a classcastexception when Hibernate calls setFooImpl() since the object passed is of type HiberbateProxy. To avoid the class cast exception I have to use the proxy interface.


Top
 Profile  
 
 Post subject: interface
PostPosted: Fri Aug 12, 2005 5:07 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
http://www.hibernate.org/hib_docs/v3/re ... tion-class
says :
Quote:
It is perfectly acceptable for the named persistent class to be an interface. You would then declare implementing classes of that interface using the <subclass> element. You may persist any static inner class. You should specify the class name using the standard form ie. eg.Foo$Bar.


it means in this case
<class name="Foo" table="FOO" >.......
<subclass.....
</class>

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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