Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Can someone please help me out in this XDoclet mapping. I am able to do DB operations using hibernate. Using many-to-many relationship here is giving me problem. I have a User Table, Role Table and UserRole mapping table, And I have given the code for my java class with XDoclet into it and also hibernate.cfg.xml file.
Thanks in Advance.............. CHEERS
Hibernate version: 2.1b]
[b]Mapping documents:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<hibernate-configuration>
<session-factory>
<!-- properties -->
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql:///catapult</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="connection.password"></property>
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<!-- mapping files -->
<mapping resource="com/touchpoint/catapult/server/entity/SeverityDef.hbm.xml"/>
<mapping resource="com/touchpoint/catapult/server/entity/CompDef.hbm.xml"/>
<mapping resource="com/touchpoint/catapult/server/security/domain/User.hbm.xml"/>
<mapping resource="com/touchpoint/catapult/server/security/domain/Role.hbm.xml"/>
</session-factory>
</hibernate-configuration>
----------------------xxxxxxxxxxxxxxxxxxxxxxxxxx---------------------------
USER CLASS WITH XDOCLET
===================
package com.touchpoint.catapult.server.security.domain;
import java.util.List;
import java.util.ArrayList;
import com.touchpoint.catapult.server.security.domain.Role;
/**
* @author GAnandjiwala
* @hibernate.class table="tblUser"
* This is an Entity Bean representing User Entity
* It has setter and getter for userId,password,fName and lName
*/
public final class User {
private int userId;
private String userName;
private String password;
private String fName;
private String lName;
private List roles;
public User(){
}
/**
* @hibernate.id
* generator-class="native"
* column="userId"
*/
public int getUserId(){
return this.userId;
}
public void setUserId(int userId){
this.userId = userId;
}
/**
* @return String userName
* @hibernate.property
* column = "userName"
*/
public String getUserName(){
return this.userName;
}
public void setUserName(String userName){
this.userName = userName;
}
/**
* @hibernate.property
* column = "password"
* @return String password
*/
public String getPassword(){
return this.password;
}
public void setPassword(String pwd){
this.password = pwd;
}
/**
*
* @hibernate.property
* column = "fName"
* @return
*/
public String getfName(){
return this.fName;
}
public void setfName(String fName){
this.fName = fName;
}
/**
* @hibernate.property
* column = "lName"
* @return
*/
public String getlName(){
return this.lName;
}
public void setlName(String lName){
this.lName = lName;
}
/**
* @hibernate.list
* table="tbluserroles"
* cascade="save-update"
* @hibernate.collection-many-to-many
* column="roleId"
* class="com.touchpoint.catapult.server.security.domain.Role"
* @hibernate.collection-key
* column="userId"
*/
public List getRoles(){
return this.roles;
}
public void setRoles(List roles){
this.roles = roles;
}
public int addRole(Role role){
return 0;
}
}
===============================================
ROLE CLASS WITH XDOCLET
package com.touchpoint.catapult.server.security.domain;
import java.util.List;
import java.util.ArrayList;
/**
* @author GAnandjiwala
* @hibernate.class table="tblRole"
* This is an Entity Bean representing Role Entity
* It has setter and getter for roleId and roleDesc
*/
public final class Role {
private int roleId;
private String roleDesc;
private List objPermissions;
public Role(){
}
/**
* @hibernate.id
* generator-class="native"
* column="roleId"
*/
public int getRoleId(){
return this.roleId;
}
public void setRoleId(int roleId){
this.roleId = roleId;
}
/**
* @hibernate.property
* column = "roleDesc"
* @return String roleDesc
*/
public String getRoleDesc(){
return this.roleDesc;
}
public void setRoleDesc(String roleDesc){
this.roleDesc = roleDesc;
}
/**
* @hibernate.list
* table="tblrolepermissions"
* cascade="save-update"
* @hibernate.collection-many-to-many
* column="permissionId"
* class="com.touchpoint.catapult.server.security.domain.Permission"
* @hibernate.collection-key
* column="roleId"
* @hibernate.collection-index
* column="permissionId"
*/
public List getPermissions(){
return this.objPermissions;
}
public void setPermission(List permissions){
this.objPermissions = permissions;
}
}
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
2005-02-22 09:32:43,718 [http8080-Processor4] INFO net.sf.hibernate.cfg.Binder
- Mapping class: com.touchpoint.catapult.server.security.domain.User -> tblUser
2005-02-22 09:32:43,718 [http8080-Processor4] ERROR net.sf.hibernate.cfg.Configu
ration - Could not configure datastore from input stream
java.lang.NullPointerException
at net.sf.hibernate.util.StringHelper.qualify(StringHelper.java:241)
at net.sf.hibernate.cfg.Binder.bindCollection(Binder.java:509)
at net.sf.hibernate.cfg.Binder$3.create(Binder.java:1441)
at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1028)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:362)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1256)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:253)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:
289)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:337
)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:102
7)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:983
)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:911)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
at com.touchpoint.catapult.server.hibernate.HibernateSessionFactory.init
(HibernateSessionFactory.java:30)
at com.touchpoint.catapult.server.dao.MysqlUserDAO.<init>(MysqlUserDAO.j
ava:48)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:308)
at java.lang.Class.newInstance(Class.java:261)
at com.touchpoint.catapult.server.dao.DAOFactory.loadDataAccessManager(D
AOFactory.java:49)
at com.touchpoint.catapult.server.dao.DAOFactory.getUserDAO(DAOFactory.j
ava:38)
at com.touchpoint.catapult.server.handler.UserHandler.<init>(UserHandler
.java:37)
at com.touchpoint.catapult.server.handler.UserHandler.getInstance(UserHa
ndler.java:29)
at org.apache.jsp.TestUser_jsp._jspService(TestUser_jsp.java:61)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
95)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
rValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:19
3)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:666)
at java.lang.Thread.run(Thread.java:534)
2005-02-22 09:32:43,921 [http8080-Processor4] ERROR com.touchpoint.catapult.serv
er.hibernate.HibernateSessionFactory - error configuring
net.sf.hibernate.MappingException: Error reading resource: com/touchpoint/catapu
lt/server/security/domain/User.hbm.xml
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:340
)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:102
7)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:983
)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:911)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:897)
at com.touchpoint.catapult.server.hibernate.HibernateSessionFactory.init
(HibernateSessionFactory.java:30)
at com.touchpoint.catapult.server.dao.MysqlUserDAO.<init>(MysqlUserDAO.j
ava:48)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:308)
at java.lang.Class.newInstance(Class.java:261)
at com.touchpoint.catapult.server.dao.DAOFactory.loadDataAccessManager(D
AOFactory.java:49)
at com.touchpoint.catapult.server.dao.DAOFactory.getUserDAO(DAOFactory.j
ava:38)
at com.touchpoint.catapult.server.handler.UserHandler.<init>(UserHandler
.java:37)
at com.touchpoint.catapult.server.handler.UserHandler.getInstance(UserHa
ndler.java:29)
at org.apache.jsp.TestUser_jsp._jspService(TestUser_jsp.java:61)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
95)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
rValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:19
3)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:666)
at java.lang.Thread.run(Thread.java:534)
Caused by: net.sf.hibernate.MappingException: java.lang.NullPointerException
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:
297)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:337
)
... 52 more
Caused by: java.lang.NullPointerException
at net.sf.hibernate.util.StringHelper.qualify(StringHelper.java:241)
at net.sf.hibernate.cfg.Binder.bindCollection(Binder.java:509)
at net.sf.hibernate.cfg.Binder$3.create(Binder.java:1441)
at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1028)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:362)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1256)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:253)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:
289)
... 53 more
Name and version of the database you are using:
MySQL DB
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
[quote][/quote]