Announcement Announcement Module
Collapse
No announcement yet.
Hibernate Axis OpenSessionViewFilter problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate Axis OpenSessionViewFilter problem

    I am having a hard time getting axis, hibernate and spring playing nicely together with my data model (Disclaimer, I am new to hibernate and spring). My datamodel has a parent -> child relationship and I am using lazy intialization. When access my model via web services the OpenSessionViewFilter throws a StackOverflowError only when the parent I am attempting to retrieve has children. Is seems that axis is having a problem working with a tree srtucture?

    Here is error :

    javax.servlet.ServletException: Servlet execution threw an exception org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter.doFilterInternal(OpenSessionInVie wFilter.java:172) org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    root cause:java.lang.StackOverflowError



    Here is my setup:

    ----------------
    Node.java
    ----------------

    public class Node implements Serializable {

    String id;
    String lockerName;
    String creatorName;
    String modifierName;
    String name;
    Date creationDate;
    Date modificationDate;
    List comments = new ArrayList();
    long version;
    Set children = new HashSet();
    Node parent;
    boolean locked;
    /**
    * @return Returns the locked.
    */
    public boolean isLocked() {
    return locked;
    }
    /**
    * @param locked The locked to set.
    */
    public void setLocked(boolean locked) {
    this.locked = locked;
    }
    /**
    * @return Returns the version.
    */
    public long getVersion() {
    return version;
    }
    /**
    * @param version The version to set.
    */
    public void setVersion(long version) {
    this.version = version;
    }
    /**
    * @return Returns the parent.
    */
    public Node getParent() {
    return parent;
    }
    /**
    * @param parent The parent to set.
    */
    public void setParent(Node parent) {
    this.parent = parent;
    }

    /**
    * @return Returns the children.
    */

    /**
    * @return Returns the creationDate.
    */
    public Date getCreationDate() {
    return creationDate;
    }
    /**
    * @param creationDate The creationDate to set.
    */
    public void setCreationDate(Date creationDate) {
    this.creationDate = creationDate;
    }
    /**
    * @return Returns the creatorName.
    */
    public String getCreatorName() {
    return creatorName;
    }
    /**
    * @param creatorName The creatorName to set.
    */
    public void setCreatorName(String creatorName) {
    this.creatorName = creatorName;
    }
    /**
    * @return Returns the id.
    */
    public String getId() {
    return id;
    }
    /**
    * @param id The id to set.
    */
    public void setId(String id) {
    this.id = id;
    }
    /**
    * @return Returns the lockerName.
    */
    public String getLockerName() {
    return lockerName;
    }
    /**
    * @param lockerName The lockerName to set.
    */
    public void setLockerName(String lockerName) {
    this.lockerName = lockerName;
    }
    /**
    * @return Returns the modificationDate.
    */
    public Date getModificationDate() {
    return modificationDate;
    }
    /**
    * @param modificationDate The modificationDate to set.
    */
    public void setModificationDate(Date modificationDate) {
    this.modificationDate = modificationDate;
    }
    /**
    * @return Returns the modifierNaqme.
    */
    public String getModifierName() {
    return modifierName;
    }
    /**
    * @param modifierNaqme The modifierNaqme to set.
    */
    public void setModifierName(String modifierName) {
    this.modifierName = modifierName;
    }
    /**
    * @return Returns the name.
    */
    public String getName() {
    return name;
    }
    /**
    * @param name The name to set.
    */
    public void setName(String name) {
    this.name = name;
    }
    /**
    * @return Returns the order.
    */
    public long getOrder() {
    return order;
    }
    /**
    * @param order The order to set.
    */
    public void setOrder(long order) {
    this.order = order;
    }

    public boolean equals(Object other) {

    if ( !(other instanceof Node) ) return false;
    Node castOther = (Node) other;
    return getId().equals(castOther.getId());
    }

    public int hashCode() {
    return id == null ? System.identityHashCode(this) :
    getId().hashCode();
    }

    public String toString()
    {
    StringBuffer buf = new StringBuffer();
    buf.append(super.toString());
    buf.append("{ ").append(getId());
    buf.append("name = ").append(getName()).append("\n");
    buf.append("version = ").append(getVersion()).append("\n");
    buf.append("creation date = ").append(getCreationDate()).append("\n");
    buf.append("creator name = ").append(getCreatorName()).append("\n");
    buf.append("modification date = ").append(getModificationDate()).append("\n");
    buf.append("modifier name = ").append(getModifierName()).append("\n");
    buf.append("}");
    return buf.toString();
    }

    long order;
    //int subType;


    public void addChild(Node aNode){
    aNode.setParent(this);
    children.add(aNode);
    }
    /**
    * @return Returns the comments.
    */
    public List getComments() {
    return comments;
    }
    /**
    * @param comments The comments to set.
    */
    public void setComments(List comments) {
    this.comments = comments;
    }
    /**
    * @param children The children to set.
    */
    public void setChildren(Set children) {
    this.children = children;
    }
    /**
    * @return Returns the children.
    */
    public Set getChildren() {
    return children;
    }
    }

    -----------------
    node.hbm.xml
    -----------------

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping package="com.siemens.macmam.model">

    <class name="Node" table="NODES" lazy="true">

    <id name="id" type="string" unsaved-value="null" >
    <column name="node_id" not-null="true"/>
    <generator class="guid"/> <!-- uuid.hex -->
    </id>
    <version name="version" type="long"/>
    <property name="name">

    </property>

    <property name="creatorName">
    <column name="creator_name" not-null="true"/>
    </property>

    <property name="creationDate">
    <column name="creator_date" not-null="true"/>
    </property>

    <property name="lockerName">
    <column name="locker_name"/>
    </property>

    <property name="modificationDate">
    <column name="modification_date" not-null="true"/>
    </property>

    <property name="modifierName">
    <column name="modifier_name" not-null="true"/>
    </property>

    <property name="locked">
    </property>

    <set name="children" lazy="true" inverse="true" cascade="save-update">
    <key column="parent"/>
    <one-to-many class="Node" />
    </set>
    <many-to-one name="parent" column="parent" cascade="none" class="Node"/>



    </class>



    </hibernate-mapping>


    ---------------------------
    HibernateBaseDao.java
    ---------------------------

    public class HibernateBaseDao extends HibernateDaoSupport implements NodeDao {

    Log log = LogFactory.getLog(getClass());


    /* (non-Javadoc)
    * @see com.siemens.macmam.model.dao.NodeDao#getRootNode()
    */
    public Node getRootNode() throws DataAccessException {
    Node rootNode = (Node)getHibernateTemplate().load(Node.class,"0000 0000-0000-0000-000000000000");
    if(rootNode == null) {
    log.error("failed to retrieve root node");
    throw new HibernateDataAccessException("failed to retrieve root node");
    }
    return rootNode;
    //Node rootNode = (Node)getHibernateTemplate().load(Node.class,"0000 0000-0000-0000-000000000000");
    //return rootNode;
    }

    }

    ---------------------------
    BrowseWebservice.java
    ---------------------------

    public class BrowseWebservice extends ServletEndpointSupport {

    Log log = LogFactory.getLog(getClass());

    ApplicationContext ac;

    public Node getRootNode() throws RemoteException {
    Node root = null;
    try {
    ac = getWebApplicationContext();
    NodeDao dao = (NodeDao) ac.getBean("nodeDao");
    root = dao.getRootNode();
    } catch (Exception e) {
    e.printStackTrace();
    log.error(e);
    throw new RemoteException(e.toString());
    }
    return root;
    }
    }

    --------------------
    hibernate.cfg.xml
    --------------------

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

    <hibernate-configuration>

    <session-factory>

    <property name="connection.datasource">java:comp/env/jdbc/macmam</property>
    <property name="show_sql">true</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Mapping files -->
    <mapping resource="node.hbm.xml"/>

    </session-factory>

    </hibernate-configuration>


    ------------------------
    myapp-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <!--
    - Application context definition for "springapp" DispatcherServlet.
    -->

    <beans>


    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="mappingResources">
    <list>
    <value>node.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="show_sql">true</prop>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQ LDialect</prop>
    </props>
    </property>

    <property name="dataSource">
    <ref bean="myDataSource"/>
    </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">

    <property name="sessionFactory"><ref local="sessionFactory"/></property>

    </bean>



    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" >
    <property name="driverClassName">
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
    <value>jdbc:mysql://localhost/macmam</value>
    </property>
    <property name="username">
    <value>root</value>
    </property>
    <property name="password">
    <value></value>
    </property>
    </bean>

    <!-- DAO -->


    <bean id="nodeDao" class="com.siemens.macmam.model.dao.impl.Hibernate BaseDao">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>





    </beans>





    ---------------
    web.xml
    ---------------

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>

    <display-name>Mac MAM</display-name>
    <description> Hibernate Mac MAM </description>

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/macmam-servlet.xml
    </param-value>
    </context-param>

    <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.O penSessionInViewFilter</filter-class>
    </filter>

    <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
    <listener-class>org.apache.axis.transport.http.AxisHTTPSessi onListener</listener-class>
    </listener>

    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>



    <servlet>
    <servlet-name>context</servlet-name>
    <servlet-class>org.springframework.web.context.ContextLoade rServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
    <servlet-name>macmam</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet>
    <servlet-name>axis</servlet-name>
    <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
    <init-param>
    <param-name>axis.development.system</param-name>
    <param-value>true</param-value>
    </init-param>

    </servlet>

    <servlet-mapping>
    <servlet-name>macmam</servlet-name>
    <url-pattern>/controller/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
    <servlet-name>axis</servlet-name>
    <url-pattern>/services/*</url-pattern>
    </servlet-mapping>


    <resource-ref>
    <description> Resource reference to a factory for java.sql.Connection instances that may be
    used for talking to a particular database that is configured in the server.xml file. </description>
    <res-ref-name>jdbc/macmam</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    <!-- Define servlets that are included in the example application -->
    <security-constraint>
    <display-name>Example Security Constraint</display-name>
    <web-resource-collection>
    <web-resource-name>Protected Area</web-resource-name>
    <!-- Define the context-relative URL(s) to be protected -->
    <url-pattern>/jsp/security/protected/*</url-pattern>
    <!-- If you list http methods, only those methods are protected -->
    <http-method>DELETE</http-method>
    <http-method>GET</http-method>
    <http-method>POST</http-method>
    <http-method>PUT</http-method>
    </web-resource-collection>
    <auth-constraint>
    <!-- Anyone with one of the listed roles may access this area -->
    <role-name>tomcat</role-name>
    <role-name>role1</role-name>
    </auth-constraint>
    </security-constraint>
    <security-role>
    <role-name>role1</role-name>
    </security-role>
    <security-role>
    <role-name>tomcat</role-name>
    </security-role>
    </web-app>
Working...
X