user1477834
user1477834

Reputation: 65

Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

Error: org.hibernate.MappingException: Unknown entity: com.myapp.struts.timesheetForm

The above error occurs when attempting to save data from a Bean within an Action class in Struts using the hibernate framework.

The main files:

timeSheet.jsp
timesheetForm.java
timeSheetAction.java

TimeSheetData.java is my pojo.

Extracting data from the database using hibernate is easy and works like a charm. timeSheet.jsp gets populated perfectly.

My timesheetaction.java is where I plan to save the updated data to the database.

I create a bean object based on the form data.

I create an object based on the timesheetdata.java

I use beanutils to copy the properties of the formbean into the pojo.

then update via the session object.

I have worked out that its null but thats as much as I can work out.

Session sess = HibernateUtil.getSessionFactory().getCurrentSession();
sess.beginTransaction();
timesheetForm formBean = (timesheetForm)form;
timeSheetData formData = new TimeSheetData();
formBean.setAdditionhours4_1(formBean.getAdditionhours1_1());
BeanUtils.copyProperties(formData, formBean);
sess.update(formData);
sess.getTransaction().commit();
sess.flush();
sess.close();

Upvotes: 0

Views: 11651

Answers (3)

Richard P.
Richard P.

Reputation: 723

Please check you hibernate mapping, this problem can be easyly addressed by changing updatable and insertable params in anotations.

For example, in my case I solved it by changing it:

@OneToMany
@JoinColumn(name = "columnPK", updatable = true, insertable = true)
private List<ObjectX> relatedElments;

with this:

@OneToMany
@JoinColumn(name = "columnPK", updatable = false, insertable = false)
private List<ObjectX> relatedElments;

The explanation is that this params prevent hibernate to update a related table while you try to insert/update other 'super' table. So, check all the hibernate anotations.

Upvotes: 0

user1477834
user1477834

Reputation: 65

Session sess = HibernateUtil.getSessionFactory().getCurrentSession();

    Transaction tx = sess.beginTransaction();
    // extract user data
    timesheetForm formBean = (timesheetForm)form;

int count = 0;
   int loopConstraint = 0;

   while(loopConstraint < dataList.size())
   {

      int ID = Integer.parseInt(dataList.get(loopConstraint).toString());
      TimeSheetData formData = (TimeSheetData) sess.load(TimeSheetData.class, ID);

   //relevant additions to database

    sess.update(formData);
      sess.flush();
      sess.clear();

   }
      tx.commit();

Upvotes: 1

PSR
PSR

Reputation: 40318

I think no records are available to update

Upvotes: 0

Related Questions