-->
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.  [ 44 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: H3 migration : could not initialize proxy
PostPosted: Fri Mar 04, 2005 12:41 pm 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
Hi Guys,

I've started to upgrade our application to Hibernate 3. I have gotten fairly far into into now having changed all our logic daos and mapping files and so on.

In testing the migration we are experiencing an exception which seems only to arise when loading a particular object. All our list() type queries work without a problem. We use Hibernate all across our various applications and all exhibit the same problem - list queries work fine, but when an operation that demands a 1 object load is performed, the same exception is thrown.

Hope you can help.

Hibernate version:
3.0 rc1

Mapping documents:

<code>
<?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 schema="dbPOF.dbo">

<class name="com.qas.newmedia.intranet.pof.dto.POF"
table="tbl_POFs">

<id name="id" type="int" column="pof_id" unsaved-value="0">
<generator class="identity" />
</id>

<property name="created" column="created" type="calendar" not-null="true" />
<property name="status" column="status" not-null="true" />
<property name="reference" column="reference" not-null="true" />
<property name="priority" column="priority" type="int" not-null="true" />
<property name="externalId" column="external_id" not-null="false" />

<property name="proxy" column="proxy" not-null="false" />
<property name="proxyFullName" column="proxy_full_name" not-null="false" />
<property name="proxyEmail" column="proxy_email" not-null="false" />

<property name="originator" column="originator" not-null="true" />
<property name="originatorFullName" column="originator_full_name" not-null="true" />
<property name="originatorEmail" column="originator_email" not-null="true" />
<property name="department" column="department" not-null="true" />
<property name="departmentCode" column="department_code" not-null="true" />
<property name="countryCode" column="country_code" not-null="true" />
<property name="authoriser" column="authoriser" not-null="true" />

<property name="currencyCode" column="currency_code" not-null="true" />
<property name="appliesTo" column="applies_to" type="calendar" not-null="true" />

<property name="netCost">
<column name="net_cost" not-null="true" sql-type="money" />
</property>

<property name="discountCost">
<column name="discount_cost" not-null="true" sql-type="money" />
</property>

<property name="carriageCost">
<column name="carriage_cost" not-null="true" sql-type="money" />
</property>

<property name="taxRate">
<column name="tax_rate" not-null="true" sql-type="money" />
</property>

<property name="taxCost">
<column name="tax_cost" not-null="true" sql-type="money" />
</property>

<property name="grossCost">
<column name="gross_cost" not-null="true" sql-type="money" />
</property>

<property name="notes">
<column name="notes" not-null="false" sql-type="varchar(4000)" />
</property>

<many-to-one name="supplier" column="supplier_id" cascade="all" unique="true" />
<many-to-one name="deliveryAddress" column="delivery_address_id" cascade="all" unique="true" />

<list name="authorisers" inverse="true" lazy="false" cascade="all">
<key column="pof_id"/>
<index column="index_col" />
<one-to-many class="com.qas.newmedia.intranet.pof.dto.Authoriser" />
</list>

<list name="lineItems" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="pof_id"/>
<index column="index_col" />
<one-to-many class="com.qas.newmedia.intranet.pof.dto.LineItem" />
</list>

<list name="invoices" inverse="true" lazy="false" cascade="all">
<key column="pof_id"/>
<index column="index_col" />
<one-to-many class="com.qas.newmedia.intranet.pof.dto.Invoice" />
</list>

<list name="actionHistory" inverse="true" lazy="true" cascade="all">
<key column="pof_id"/>
<index column="index_col" />
<one-to-many class="com.qas.newmedia.intranet.pof.dto.Action" />
</list>

</class>

<class name="com.qas.newmedia.intranet.pof.dto.Authoriser"
table="tbl_Authorisers">

<id name="id" type="int" column="authoriser_id" unsaved-value="0">
<generator class="identity" />
</id>

<property name="empId" column="emp_id" not-null="true" />
<property name="username" column="username" not-null="true" />
<property name="fullName" column="full_name" not-null="true" />
<property name="email" column="email" not-null="true" />

<many-to-one name="purchaseOrderForm" column="pof_id" not-null="true" />

<property name="index" type="int" update="true" insert="true" column="index_col" />

</class>

<class name="com.qas.newmedia.intranet.pof.dto.LineItem"
table="tbl_LineItems">

<id name="id" type="int" column="line_item_id" unsaved-value="0">
<generator class="identity" />
</id>

<property name="code" column="code" not-null="false" />
<property name="description" column="description" not-null="true" />
<property name="function" column="fn" not-null="false" />
<property name="quantity" column="quantity" type="int" not-null="true" />

<property name="unitPrice">
<column name="unit_price" not-null="true" sql-type="money" />
</property>

<property name="taxType" column="tax_type" not-null="true" />

<property name="netCost">
<column name="net_cost" not-null="true" sql-type="money" />
</property>

<property name="notes">
<column name="notes" not-null="false" sql-type="varchar(4000)" />
</property>

<many-to-one name="purchaseOrderForm" column="pof_id" not-null="true" />

<property name="index" type="int" update="true" insert="true" column="index_col" />

</class>

<class name="com.qas.newmedia.intranet.pof.dto.Supplier"
table="tbl_Suppliers">

<id name="id" type="int" column="supplier_id" unsaved-value="0">
<generator class="identity" />
</id>

<property name="code" column="code" not-null="true" />
<many-to-one name="address" column="address_id" cascade="all" unique="true" />

</class>

<class name="com.qas.newmedia.intranet.pof.dto.IntlCompanyDetail"
table="tbl_IntlCompanyDetails">

<id name="id" type="int" column="intl_comp_det_id" unsaved-value="0">
<generator class="identity" />
</id>

<property name="company" column="company" not-null="false" />
<property name="contact" column="contact" not-null="false" />
<property name="telephone" column="telephone" not-null="false" />
<property name="fax" column="fax" not-null="false" />
<property name="email" column="email" not-null="false" />
<property name="web" column="web" not-null="false" />
<property name="addressLine1" column="address_line_1" not-null="false" />
<property name="addressLine2" column="address_line_2" not-null="false" />
<property name="addressLine3" column="address_line_3" not-null="false" />
<property name="addressLine4" column="address_line_4" not-null="false" />
<property name="addressLine5" column="address_line_5" not-null="false" />
<property name="addressLine6" column="address_line_6" not-null="false" />
<property name="addressLine7" column="address_line_7" not-null="false" />

</class>

<class name="com.qas.newmedia.intranet.pof.dto.Action"
table="tbl_Actions">

<id name="id" type="int" column="action_id" unsaved-value="0">
<generator class="identity" />
</id>

<property name="created" column="created" type="calendar" not-null="false" />
<property name="username" column="username" not-null="false" />
<property name="fullName" column="fullName" not-null="false" />
<property name="department" column="department" not-null="false" />
<property name="action" column="action" not-null="false" />
<property name="comment" column="comment" not-null="false" />

<many-to-one name="purchaseOrderForm" column="pof_id" not-null="true" />

<property name="index" type="int" update="true" insert="true" column="index_col" />
</class>

<class name="com.qas.newmedia.intranet.pof.dto.Invoice"
table="tbl_Invoices">

<id name="id" type="int" column="invoice_id" unsaved-value="0">
<generator class="identity" />
</id>

<property name="date" column="invoice_date" type="calendar" not-null="false" />
<property name="number" column="invoice_number" not-null="false" />

<many-to-one name="purchaseOrderForm" column="pof_id" not-null="true" />

<property name="index" type="int" update="true" insert="true" column="index_col" />
</class>

</hibernate-mapping>
</code>

Code between sessionFactory.openSession() and session.close():

<code>
public POF loadFullPurchaseOrderForm(IQUser user, Integer id) throws POFException {

POF pof = null;

try {
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();

String userSearchPermissions = getUserSearchPermissions(user);

String hql =
"from POF as p " +
" left join fetch p.lineItems " +
" left join fetch p.authorisers a " +
" left join fetch p.actionHistory " +
" left join fetch p.invoices " +
"where p.id = :pofId";

if (! userIsAdminAny(user)) {
hql +=
" and (" +
" (a.username= '" + user.getUsername() + "') or " +
" (p.proxy = '" + user.getUsername() + "') or " +
" (p.departmentCode = '" + user.getCostCode() + "' and " +
" p.countryCode = '" + user.getCountry() + "') ";

if (userSearchPermissions != null) {
hql += "or ((p.countryCode + '/' + p.departmentCode) in " +
"(" + userSearchPermissions + ")) ";
}

hql += ")";
}

logger.debug(user.getUsername() + ": " + hql);

Query q = session.createQuery(hql);
q.setParameter("pofId", id);
List<POF> list = q.list();
if (list.size() > 0) {
pof = list.get(0);
}

tx.commit();
HibernateUtil.closeSession(session);

} catch (Exception e) {
logger.error(e + " " + e.getMessage());
throw new POFException(e.getMessage());
}

return pof;
}
</code>

Full stack trace of any exception that occurs:

<code>
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
at com.qas.newmedia.intranet.pof.dto.Supplier$$EnhancerByCGLIB$$a8640bcf.toString(<generated>)
at java.lang.String.valueOf(String.java:2577)
at java.lang.StringBuilder.append(StringBuilder.java:116)
at com.qas.newmedia.intranet.pof.dto.POF.toString(POF.java:466)
at java.lang.String.valueOf(String.java:2577)
at java.lang.StringBuilder.append(StringBuilder.java:116)
at com.qas.newmedia.intranet.pof.actions.BaseAction.loadPOF(BaseAction.java:317)
at com.qas.newmedia.intranet.pof.actions.view.ViewAction.doWork(ViewAction.java:49)
at com.qas.newmedia.intranet.iq.actions.SecuredBaseAction.execute(SecuredBaseAction.java:188)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1158)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.qas.newmedia.common.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:65)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:526)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:305)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:383)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
</code>

Name and version of the database you are using:

The generated SQL (show_sql=true):

N/A

Debug level Hibernate log excerpt:

N/A


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 04, 2005 12:52 pm 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
here's another example without any collections ...

Code:

<?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 schema="db_iQ.dbo">

    <class name="com.qas.newmedia.intranet.iq.dto.admin.Node"
      table="tbl_NavigationTree">

        <id name="id" type="int" column="node_id" unsaved-value="0">
           <generator class="identity" />
       </id>
            
        <property name="parentId" type="int" column="parent_node_id" not-null="true" />
      <property name="groupOrder" type="int" column="group_order" not-null="true" />
      <property name="path" column="path" not-null="false" />
      
      <property name="title" column="title" not-null="false" />
      <property name="titleFull" column="title_full" not-null="true" />
      <property name="narrative" column="narrative" not-null="false" />
      <property name="viewType" column="view_type" not-null="false" />
      <property name="viewOverride" column="view_override" not-null="false" />
      <property name="viewRedirect" column="view_redirect" not-null="false" />
      <property name="viewRedirectUseNewWindow" column="view_redirect_use_new_win" not-null="false" />
      <property name="viewRedirectParams" column="view_redirect_params" not-null="false" />
      <property name="viewContent" column="view_content" not-null="false" />
      <property name="publishingDisabled" column="publishing_disabled" not-null="false" />
      <property name="checkinAdditional" column="checkin_additional" not-null="false" />
      <property name="importSearch" column="import_search" not-null="false" />
      <property name="maskResults" column="mask_results" not-null="false" />
      <property name="customSearchFilter" column="custom_search_filter" not-null="false" />
      <property name="customSearchFilterDefaults" column="custom_search_filter_defaults" not-null="false" />
      <property name="validateTemplate" column="validate_template" not-null="false" />
      <property name="neverExpireControl" column="never_expire_control" not-null="false" />
      <property name="roleMask" column="role_mask" not-null="false" />
      <property name="resultsFormat" column="results_format" not-null="false" />
      <property name="navigationOrderOverride" column="nav_order_override" not-null="false" /> 
      <property name="allowEmail" column="allow_email" not-null="false" />
      <property name="vqlSearch" column="vql_search" not-null="false" />
      <property name="searchPath" column="search_path" not-null="false" />
      
   </class>   

</hibernate-mapping>


CALL
====

[code]
public Node load(Integer id) throws AdminException {

Node node = null;

try {
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();

node = (Node) session.load(Node.class, id);

tx.commit();
HibernateUtil.closeSession(session);

} catch (HibernateException hE) {
throw new AdminException(hE.getMessage());
}

return node;
}
[code]

So, by now, I've called the Node object out and back into my Servlet, no Session is kept live. Then I do in the servlet

node.setNumSiblings(admin.countChildren(node.getParentId()) - 1);

which calls another Hibernate method

[code]
public int countChildren(int parentId) throws AdminException {

int numSiblings = 0;

try {
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();

numSiblings = ((Integer) session.createQuery(
"select count(*) from Node as node where " +
"parent_node_id = " + parentId).iterate().next()).intValue();

tx.commit();
HibernateUtil.closeSession(session);

} catch (HibernateException hE) {
throw new AdminException(hE.getMessage());
}

return numSiblings;
}
[/code]

And it is here that the exception occurs ...

[code]
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
at com.qas.newmedia.intranet.iq.dto.admin.Node$$EnhancerByCGLIB$$91c24149.getParentId(<generated>)
at com.qas.newmedia.intranet.iq.actions.admin.LoadNodeAction.doWork(LoadNodeAction.java:33)
at com.qas.newmedia.intranet.iq.actions.admin.AdminBaseAction.execute(AdminBaseAction.java:20)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1158)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.qas.newmedia.common.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:65)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:526)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:305)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:383)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
[/code][/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 04, 2005 1:04 pm 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
i have some more detailed hibernate logging leading up to the exception too ..

Code:
2005-03-04 16:41:09,271 - DEBUG (org.hibernate.impl.SessionImpl:229) - opened session
2005-03-04 16:41:09,271 - DEBUG (org.hibernate.transaction.JDBCTransaction:46) - begin
2005-03-04 16:41:09,271 - DEBUG (org.hibernate.jdbc.AbstractBatcher:379) - opening JDBC connection
2005-03-04 16:41:09,271 - DEBUG (org.hibernate.transaction.JDBCTransaction:50) - current autocommit status: true
2005-03-04 16:41:09,286 - DEBUG (org.hibernate.transaction.JDBCTransaction:52) - disabling autocommit
2005-03-04 16:41:09,302 - DEBUG (org.hibernate.event.def.DefaultLoadEventListener:193) - loading entity: [com.qas.newmedia.intranet.iq.dto.admin.Node#5]
2005-03-04 16:41:09,302 - DEBUG (org.hibernate.event.def.DefaultLoadEventListener:240) - creating new proxy for entity
2005-03-04 16:41:09,317 - DEBUG (com.qas.newmedia.intranet.iq.logic.admin.AdminLogic:153) - node.id=5
2005-03-04 16:41:09,317 - DEBUG (org.hibernate.transaction.JDBCTransaction:83) - commit
2005-03-04 16:41:09,317 - DEBUG (org.hibernate.impl.SessionImpl:292) - automatically flushing session
2005-03-04 16:41:09,333 - DEBUG (org.hibernate.jdbc.JDBCContext:208) - before transaction completion
2005-03-04 16:41:09,349 - DEBUG (org.hibernate.impl.SessionImpl:337) - before transaction completion
2005-03-04 16:41:09,349 - DEBUG (org.hibernate.transaction.JDBCTransaction:96) - committed JDBC Connection
2005-03-04 16:41:09,349 - DEBUG (org.hibernate.jdbc.JDBCContext:213) - after transaction completion
2005-03-04 16:41:09,349 - DEBUG (org.hibernate.impl.SessionImpl:353) - after transaction completion
2005-03-04 16:41:09,349 - DEBUG (org.hibernate.transaction.JDBCTransaction:157) - re-enabling autocommit
2005-03-04 16:41:09,364 - DEBUG (org.hibernate.impl.SessionImpl:246) - closing session
2005-03-04 16:41:09,364 - DEBUG (org.hibernate.jdbc.AbstractBatcher:394) - closing JDBC connection (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)
2005-03-04 16:41:09,364 - DEBUG (org.hibernate.jdbc.JDBCContext:213) - after transaction completion
2005-03-04 16:41:09,364 - DEBUG (org.hibernate.impl.SessionImpl:353) - after transaction completion
2005-03-04 16:41:09,380 - ERROR (org.hibernate.LazyInitializationException:19) - could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
   at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
   at com.qas.newmedia.intranet.iq.dto.admin.Node$$EnhancerByCGLIB$$91c24149.getParentId(<generated>)
   at com.qas.newmedia.intranet.iq.actions.admin.LoadNodeAction.doWork(LoadNodeAction.java:29)
   at com.qas.newmedia.intranet.iq.actions.admin.AdminBaseAction.execute(AdminBaseAction.java:20)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1158)
   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at com.qas.newmedia.common.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:65)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:526)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:305)
   at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:383)
   at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:745)
   at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
   at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:868)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Thread.java:595)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 04, 2005 1:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Read the migration guide


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 04, 2005 1:14 pm 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
Thanks Gavin,

I have read the migration guide.

I changed all our queries to use createQuery, all package imports, mapping DTDs changes and so fourth.

I do not believe there is anything else listed in the migration guide that I need to change, that is why I am asking for help. I've just taken another look, and I still don't know what you might be referring to.

Could you perhaps point me in a more direct location?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 04, 2005 1:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Metadata Changes
Association fetching strategies

Since it is best practice to map almost all classes and collections using lazy="true", that is now the default. Existing applications will need to explicitly specify lazy="false" on all non-lazy class and collection mappings.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 04, 2005 1:33 pm 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
Hi,

Thanks for coming back to me.

But I illustrated subsequently in this post that the same error occurs using a mapping that contains nothing but properties and therefore no need to specify lazy associations (the Node.xml example above).

Furhtermore, the hibernate detailed logging showed that the object was actually loaded, and the exception was thrown after it closed the transaction!?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 04, 2005 1:45 pm 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
I've tested what you said, first by checking and found that all our associations do specify lazy one way or another.

Secondly, I then removed all our HBM mapping except for the very basic one for Node (further up in this post) which only specifies properties.

The error continues to occur in this instance also, so I don't see how it can be anything to do with lazy?

Your help is appreciated, thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 04, 2005 1:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
As per the Hibernate documentation, load() returns proxies.

Stop arguing with me, and obey the migration guide!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 04, 2005 1:58 pm 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
ok, i've worked around this by not using load(), and doing it with a createQuery instead.

i don't understand it although i would like to - although i am sure it makes sense to you, the fact that i reduced the use case to a situation where lazy is not even needed makes it confusing for me.

thanks for your help anyway, i'll use this workaround.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 07, 2005 8:47 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
We (the development team) would really appreciate some further assistance/insight into this, because as it stands most of our apps have broken under hibernate 3 (on our development boxes of course not production which has not been upgraded), ALL with this same org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed error, despite that we take care in our mapping files to always specify lazy attribute.

Most Hibernate interactions are fine - loading normal lists of objects, saving, updating single objects. We solved a lot of these errors by converting load() calls into get() calls.

But we are left with 2 places that remain very problematic, and they are both session.createQuery .list() calls.

Query 1
=====

Code:
POF pof = null;

           String hql =
               "from POF as p " +
                "   left join fetch p.lineItems " +
                "   left join fetch p.authorisers a " +
                "   left join fetch p.actionHistory " +
                "   left join fetch p.invoices " +
                "where p.id = ?";

Query q = session.createQuery(hql).setInteger(0, id.intValue());
            List<POF> list = q.list();
           
            if (! list.isEmpty()) {
                pof = list.get(0);
            }


Query 2
======

Code:
List<RenewalAccount> list = session.createQuery(
            "from RenewalAccount as ra " +
               "   left join fetch ra.renewalItems " +
               "where ra.id = ?").
               setInteger(0, id.intValue()).list();


I am hoping that other users or the team want people to upgrade to Hibernate 3 and might shed more light on this than Gavin gave us credit for.

Your help and explanation would be very much appreciated.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 07, 2005 9:41 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
THe most trivial way to solve this migration problem is to implement filter to close session and to remove all "close" calls in code (or use session wrapper with fake "close"). Probably you will need to increase buffer size for scalability too "ServletResponse.setBufferSize(int)", filter can block to write response before to close database connection.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 07, 2005 9:54 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
Hi,

But we use a clear 3 tier architecture. Request -> Struts Action -> DAO + Hibernate (session open AND close) -> Struts Action -> User UI.

I understand the filter mechanism as I just read it in the manual but I think we'd have to spend a bit of time implementing that another time.

We've had to revert back to Hibernate 2 where everything works until we have time to figure out what is so different in H3.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 07, 2005 9:56 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
Is it the case with H3 that even though our DAO is fetching all associations on our object and then closing the session, when the view is rendered in a JSP, that those associations have been closed/removed and that this is not the case in H2?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 07, 2005 10:17 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Does H3 support fetching of more than a single association in a single query?
Code:
String hql =
               "from POF as p " +
                "   left join fetch p.lineItems " +
                "   left join fetch p.authorisers a " +
                "   left join fetch p.actionHistory " +
                "   left join fetch p.invoices " +
                "where p.id = ?";


Suppose I should look it up...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 44 posts ]  Go to page 1, 2, 3  Next

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.