Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8792357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:58:05+00:00 2026-06-13T22:58:05+00:00

I am trying to write a stock management system. But now I have a

  • 0

I am trying to write a stock management system. But now I have a few question. Please help me to sort out these problems.

I have 2 entities. Item and ItemPrice. Item has one or more ItemPrice

When I try to save Item object, it works fine; but when I try to retrieve details from database, it gives following Exception stack trace.

org.hibernate.HibernateException: Found shared references to a collection: com.pos.entities.ItemGroup.items
Hibernate: select itemmodel0_.id as id9_, itemmodel0_.item_model as item2_9_, itemmodel0_.status as status9_ from smartpos.item_model itemmodel0_ where (itemmodel0_.status=? )
Hibernate: select itemsize0_.id as id3_, itemsize0_.item_size as item2_3_, itemsize0_.status as status3_ from smartpos.item_size itemsize0_ where (itemsize0_.status=? )
    at org.hibernate.engine.Collections.processReachableCollection(Collections.java:163)
    at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:37)
    at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
    at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
    at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:138)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    at com.pos.dao.ItemDaoImpl.getItem(ItemDaoImpl.java:761)
    at com.pos.manager.ItemManager.getItem(ItemManager.java:296)
    at com.pos.ui.ItemDefinitionForm$RefreshTask.doInBackground(ItemDefinitionForm.java:464)
    at com.pos.ui.ItemDefinitionForm$RefreshTask.doInBackground(ItemDefinitionForm.java:458)
    at javax.swing.SwingWorker$1.call(SwingWorker.java:277)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at javax.swing.SwingWorker.run(SwingWorker.java:316)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
Nov 7, 2012 12:03:42 PM org.hibernate.LazyInitializationException 
SEVERE: failed to lazily initialize a collection of role: com.pos.entities.Item.itemPrices, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.pos.entities.Item.itemPrices, no session or session was closed
    at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
    at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
    at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:97)
    at org.hibernate.collection.PersistentSet.size(PersistentSet.java:139)
    at com.pos.ui.ItemDefinitionForm$RefreshTask.doInBackground(ItemDefinitionForm.java:520)
    at com.pos.ui.ItemDefinitionForm$RefreshTask.doInBackground(ItemDefinitionForm.java:458)
    at javax.swing.SwingWorker$1.call(SwingWorker.java:277)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at javax.swing.SwingWorker.run(SwingWorker.java:316)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.pos.entities.Item.itemPrices, no session or session was closed
    at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
    at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
    at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:97)
    at org.hibernate.collection.PersistentSet.size(PersistentSet.java:139)
    at com.pos.ui.ItemDefinitionForm$RefreshTask.doInBackground(ItemDefinitionForm.java:520)
    at com.pos.ui.ItemDefinitionForm$RefreshTask.doInBackground(ItemDefinitionForm.java:458)
    at javax.swing.SwingWorker$1.call(SwingWorker.java:277)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at javax.swing.SwingWorker.run(SwingWorker.java:316)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)

This is entity class files.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Nov 3, 2012 10:36:51 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class catalog="smartpos" name="com.pos.entities.ItemPrice" table="item_price" lazy="false">
<id name="id" type="java.lang.Integer">
  <column name="id"/>
  <generator class="identity"/>
</id>
<many-to-one class="com.pos.entities.Item" fetch="select" name="item">
  <column name="item_id" not-null="true"/>
</many-to-one>
<many-to-one class="com.pos.entities.PriceList" fetch="select" name="priceList">
  <column name="price_list_id" not-null="true"/>
</many-to-one>
<property name="price" type="float">
  <column name="price" not-null="true" precision="12" scale="0"/>
</property>

Item Entity

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Nov 3, 2012 10:36:51 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class catalog="smartpos" lazy="false" name="com.pos.entities.Item" table="item">
<id name="id" type="java.lang.Integer">
  <column name="id"/>
  <generator class="identity"/>
</id>
<many-to-one class="com.pos.entities.ItemColor" fetch="select" name="itemColor">
  <column name="item_color_id" not-null="true"/>
</many-to-one>
<many-to-one class="com.pos.entities.ItemModel" fetch="select" name="itemModel">
  <column name="item_model_id" not-null="true"/>
</many-to-one>
<many-to-one class="com.pos.entities.ItemGrade" fetch="select" name="itemGrade">
  <column name="item_grade_id" not-null="true"/>
</many-to-one>
<many-to-one class="com.pos.entities.BusinessPartner" fetch="select" name="businessPartner">
  <column name="supplier_id" not-null="true"/>
</many-to-one>
<many-to-one class="com.pos.entities.ItemSize" fetch="select" name="itemSize">
  <column name="item_size_id" not-null="true"/>
</many-to-one>
<many-to-one class="com.pos.entities.Login" fetch="select" name="login">
  <column name="login_id" not-null="true"/>
</many-to-one>
<many-to-one class="com.pos.entities.ItemGroup" fetch="select" name="itemGroup">
  <column name="item_group_id" not-null="true"/>
</many-to-one>
<many-to-one class="com.pos.entities.ItemBrand" fetch="select" name="itemBrand">
  <column name="item_brand_id" not-null="true"/>
</many-to-one>
<property name="itemCode" type="string">
  <column length="50" name="item_code" not-null="true" unique="true"/>
</property>
<property name="itemName" type="string">
  <column length="200" name="item_name" not-null="true"/>
</property>
<property name="shortName" type="string">
  <column length="100" name="short_name" not-null="true"/>
</property>
<property name="barcode" type="string">
  <column length="50" name="barcode" not-null="true"/>
</property>
<property name="warrentyItem" type="byte">
  <column name="warrenty_item" not-null="true"/>
</property>
<property name="taxableItem" type="byte">
  <column name="taxable_item" not-null="true"/>
</property>
<property name="status" type="byte">
  <column name="status" not-null="true"/>
</property>
<property name="createdDate" type="timestamp">
  <column length="19" name="created_date" not-null="true"/>
</property>
<property name="batchSerial" type="byte">
  <column name="batch_serial" not-null="true"/>
</property>
<property name="warrentyPeriod" type="int">
  <column name="warrenty_period" not-null="true"/>
</property>
<set inverse="true" name="itemPrices" cascade="save-update">
  <key>
    <column name="item_id" not-null="true"/>
  </key>
  <one-to-many class="com.pos.entities.ItemPrice"/>
</set>

GUI Coding

headers = new SupportedMethod().getTableHeaderValues(tblItemPrice);
System.out.println("sdff" + item.getItemPrices().size());
itemPriceSet = item.getItemPrices();
Iterator it = itemPriceSet.iterator();

while (it.hasNext()) {
    ItemPrice ip = (ItemPrice) it.next();
    Vector<Object> oneRow = new Vector<Object>();

    oneRow.add(ip.getId());
    oneRow.add(ip.getPriceList().getPriceListName());
    oneRow.add(Float.toString(ip.getPrice()));

    tableData.add(oneRow);
}
tblItemPrice.setModel(new DefaultTableModel(tableData, headers));

cascade is OK, and I already set lazy=false, but it throws Exception.
Please anyone help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:58:05+00:00Added an answer on June 13, 2026 at 10:58 pm

    These lines from stacktrace say that your Item.itemPrices set uses lazy initialization:

    collection of role: com.pos.entities.Item.itemPrices, no session or session was closed at
    org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
    ...
    

    So please add lazy=”false” to itemPrices collection:

    <set inverse="true" name="itemPrices" lazy="false" fetch="select" cascade="save-update">
      <key>
        <column name="item_id" not-null="true"/>
      </key>
      <one-to-many class="com.pos.entities.ItemPrice"/>
    </set>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple stock check program, and I have a Table
I'm trying to write a program, but I can't figure out why my private
I am trying to do a simple sort in a DataTable but have no
I have been trying to write a recursive function that searches a stack, but
I'm trying to write some code using posix threads but I'm stuck from the
I am trying write a function that generates simulated data but if the simulated
I am currently trying to write a regular expression to pull links out of
I'm trying to write an app using GtkClutter but I can't get the actors
I am trying to write merge sort and stuck here. What is the problem
I'm trying to write a Linux kernel module, but I'm stuck just writing some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.