Hi!
I'm new to Hibernate and am having a problem I cannot seem to get past. I've been struggling with this for a couple days, and I'm out of options. I know I'm missing something very obvious, and very noobish, but I've had no luck. I've even read the Annotations manual cover to cover.
So here goes. I have a very simple setup:
Code:
@Entity
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private String _username;
private long _id;
private Set<Campaign> _campaigns = new HashSet<Campaign>();
@Id @GeneratedValue(strategy = GenerationType.AUTO)
public long getId() { return _id; }
public void setId(long id) { _id = id; }
@Column(nullable = false, unique = true, length = 32)
public String getUsername() { return _username; }
public void setUsername(String username) { _username = username; }
@OneToMany (mappedBy="user")
public Set<Campaign> getCampaigns() { return _campaigns; }
public void setCampaigns(Set<Campaign> campaigns) { _campaigns = campaigns; }
}
@Entity
public class Campaign implements Serializable {
private static final long serialVersionUID = 1L;
private String _name;
private User _user;
private long _id;
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public long getId() { return _id; }
public void setId (long id) { _id = id; }
@Column(nullable = false, unique = false )
public String getName() { return _name; }
public void setName (String name) { _name = name; }
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn (name="user_fk")
public User getUser() { return _user; }
public void setUser (User user) { _user = user; }
}
When my webapp starts, I get the following error message in my logs:
FATAL - org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.wygand.dnd.User.campaigns[com.wygand.dnd.Campaign]
I've tried various annotations, but nothing works.
Hibernate version: 3.2
Mapping documents: in hibernate.cfg.xml I have:
<!-- Persistent classes -->
<mapping class="com.wygand.dnd.Campaign"/>
<mapping class="com.wygand.dnd.User"/>
Code between sessionFactory.openSession() and session.close():
// Just to test
List users = HibernateUtil.getSession().createCriteria(User.class).list();
List campaigns = HibernateUtil.getSession().createCriteria(Campaign.class).list();
Full stack trace of any exception that occurs:
org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.wygand.dnd.User.campaigns[com.wygand.dnd.Campaign]
org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1068)
org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:600)
org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:541)
org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1136)
org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
com.wygand.dnd.session.HibernateUtil.<clinit>(HibernateUtil.java:18)
com.wygand.dnd.servlet.DispatchController.index(DispatchController.java:38)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473)
org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Name and version of the database you are using:
$ mysql --version
mysql Ver 14.12 Distrib 5.0.51a, for debian-linux-gnu (i486) using readline 5.2
The generated SQL (show_sql=true):
none being generated
Debug level Hibernate log excerpt:
INFO - Hibernate Annotations 3.3.1.GA
INFO - Hibernate 3.2.6
INFO - hibernate.properties not found
INFO - Bytecode provider name : cglib
INFO - using JDK 1.4 java.sql.Timestamp handling
INFO - configuring from resource: /hibernate.cfg.xml
INFO - Configuration resource: /hibernate.cfg.xml
DEBUG - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
DEBUG - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
DEBUG - located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
DEBUG - hibernate.connection.driver_class=com.mysql.jdbc.Driver
DEBUG - hibernate.connection.url=jdbc:mysql://hostname/db
DEBUG - hibernate.connection.username=xxxxxxxx
DEBUG - hibernate.connection.password=xxxxxxxx
DEBUG - hibernate.connection.pool_size=10
DEBUG - show_sql=true
DEBUG - dialect=org.hibernate.dialect.MySQLDialect
DEBUG - hibernate.hbm2ddl.auto=update
DEBUG - null<-org.dom4j.tree.DefaultAttribute@f5f5a [Attribute: name class value "com.wygand.dnd.Campaign"]
DEBUG - null<-org.dom4j.tree.DefaultAttribute@9fab8d [Attribute: name class value "com.wygand.dnd.User"]
INFO - Configured SessionFactory: null
DEBUG - properties: {show_sql=true, java.vendor=Apple Inc., sun.java.launcher=SUN_STANDARD, catalina.base=/usr/local/tomcat, hibernate.connection.url=jdbc:mysql://www.wygand.com/dnd, sun.management.compiler=HotSpot Client Compiler, catalina.useNaming=true, os.name=Mac OS X, sun.boot.class.path=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/charsets.jar, java.util.logging.config.file=/usr/local/tomcat/conf/logging.properties, java.vm.specification.vendor=Sun Microsystems Inc., java.runtime.version=1.5.0_13-b05-237, user.name=rjw, shared.loader=, awt.nativeDoubleBuffering=true, tomcat.util.buf.StringCache.byte.enabled=true, user.language=en, java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory, sun.boot.library.path=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries, webapp.root=/usr/local/tomcat/webapps/dnd/, dialect=org.hibernate.dialect.MySQLDialect, java.version=1.5.0_13, java.util.logging.manager=org.apache.juli.ClassLoaderLogManager, user.timezone=America/Los_Angeles, sun.arch.data.model=32, http.nonProxyHosts=local|*.local|169.254/16|*.169.254/16, java.endorsed.dirs=/usr/local/tomcat/endorsed, sun.cpu.isalist=, sun.jnu.encoding=MacRoman, file.encoding.pkg=sun.io, package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,sun.beans., file.separator=/, java.specification.name=Java Platform API Specification, java.class.version=49.0, user.country=US, java.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home, java.vm.info=mixed mode, sharing, os.version=10.5.4, path.separator=:, java.vm.version=1.5.0_13-119, hibernate.connection.password=dnd, java.awt.printerjob=apple.awt.CPrinterJob, sun.io.unicode.encoding=UnicodeLittle, awt.toolkit=apple.awt.CToolkit, hibernate.connection.username=dnd, socksNonProxyHosts=local|*.local|169.254/16|*.169.254/16, ftp.nonProxyHosts=local|*.local|169.254/16|*.169.254/16, package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper., java.naming.factory.url.pkgs=org.apache.naming, user.home=/Users/rjw, java.specification.vendor=Sun Microsystems Inc., hibernate.hbm2ddl.auto=update, java.library.path=.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java, java.vendor.url=http://www.apple.com/, hibernate.connection.driver_class=com.mysql.jdbc.Driver, java.vm.vendor=Apple Inc., gopherProxySet=false, hibernate.dialect=org.hibernate.dialect.MySQLDialect, common.loader=${catalina.home}/lib,${catalina.home}/lib/*.jar, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, java.class.path=:/usr/local/tomcat/bin/bootstrap.jar, hibernate.bytecode.use_reflection_optimizer=false, java.vm.specification.name=Java Virtual Machine Specification, java.vm.specification.version=1.0, catalina.home=/usr/local/tomcat, sun.cpu.endian=little, sun.os.patch.level=unknown, java.io.tmpdir=/usr/local/tomcat/temp, java.vendor.url.bug=http://bugreport.apple.com/, server.loader=, os.arch=i386, java.awt.graphicsenv=apple.awt.CGraphicsEnvironment, java.ext.dirs=/Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/ext, mrj.version=1040.1.5.0_13-237, user.dir=/usr/local/tomcat/bin, line.separator=
, java.vm.name=Java HotSpot(TM) Client VM, file.encoding=MacRoman, java.specification.version=1.5, hibernate.show_sql=true, hibernate.connection.pool_size=10}
DEBUG - Search not present in classpath, ignoring event listener registration
DEBUG - Preparing to build session factory with filters : {}
DEBUG - Execute first pass mapping processing
DEBUG - Process hbm files
DEBUG - Process annotated classes
INFO - Binding entity from annotated class: com.wygand.dnd.User
DEBUG - Binding column DTYPE unique false
DEBUG - Import with entity name=User
INFO - Bind entity com.wygand.dnd.User on table User
DEBUG - Processing com.wygand.dnd.User property annotation
DEBUG - Processing annotations of com.wygand.dnd.User.id
DEBUG - Binding column id unique false
DEBUG - id is an id
DEBUG - building SimpleValue for id
DEBUG - Building property id
TRACE - Cascading id with null
DEBUG - Bind @Id on id
DEBUG - Processing annotations of com.wygand.dnd.User.campaigns
DEBUG - Binding column null unique false
DEBUG - Binding column campaigns unique false
DEBUG - Binding column null unique false
DEBUG - Binding column element unique false
DEBUG - Binding column mapkey unique false
DEBUG - Binding column null unique false
DEBUG - Binding column null unique false
DEBUG - Binding column null unique false
DEBUG - Collection role: com.wygand.dnd.User.campaigns
DEBUG - Building property campaigns
TRACE - Cascading campaigns with none
DEBUG - Processing annotations of com.wygand.dnd.User.username
DEBUG - Binding column username unique true
DEBUG - binding property username with lazy=false
DEBUG - building SimpleValue for username
DEBUG - Building property username
TRACE - Cascading username with null
DEBUG - processing fk mappings (*ToOne and JoinedSubclass)
DEBUG - processing extends queue
DEBUG - processing collection mappings
DEBUG - Second pass for collection: com.wygand.dnd.User.campaigns
DEBUG - Binding a collection of element: com.wygand.dnd.User.campaigns
FATAL - org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.wygand.dnd.User.campaigns[com.wygand.dnd.Campaign]
Thanks!