-->
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.  [ 5 posts ] 
Author Message
 Post subject: Table Insert Error
PostPosted: Fri Sep 30, 2005 10:15 pm 
Beginner
Beginner

Joined: Mon Sep 19, 2005 3:59 pm
Posts: 31
Hi there,
I am trying to insert new record in table, but I got error:

Quote:
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into systemuser (active, role, username, pin, name) values (1, a, b, c, d) was aborted. Call getNextException to see the cause.


it seems the sql statment wrong, it should be like this.

insert into systemuser (active, role, username, pin, name) values (true, 'a', 'b','c','d');

Could you pls give me some ideas?

thanks

Lamborghini


Top
 Profile  
 
 Post subject: My code:
PostPosted: Fri Sep 30, 2005 10:25 pm 
Beginner
Beginner

Joined: Mon Sep 19, 2005 3:59 pm
Posts: 31
Code:
   public void saveSystemuser(Systemuser systemuser) {

      /* a Hibernate session */

      Session session = null;

      /* we always need a transaction */

      Transaction tx = null;
      try {

         /* get session of the current thread */

         session = HibernateSessionFactory.currentSession();
         tx = session.beginTransaction();
         if (systemuser.getUserid() == null
               || systemuser.getUserid().intValue() == 0)
            session.save(systemuser);
         else {
            Systemuser toBeUpdated = (Systemuser) session.get(
                  Systemuser.class, systemuser.getUserid());
            toBeUpdated.setActive(systemuser.getActive());
            toBeUpdated.setRole(systemuser.getRole());
            toBeUpdated.setUsername(systemuser.getUsername());
            toBeUpdated.setPin(systemuser.getPin());
            toBeUpdated.setName(systemuser.getName());
            toBeUpdated.setPersonalid(systemuser.getPersonalid());
            toBeUpdated.setRegdate(systemuser.getRegdate());
            toBeUpdated.setBusiness(systemuser.getBusiness());
            toBeUpdated.setContact(systemuser.getContact());
            toBeUpdated.setPhone(systemuser.getPhone());
            toBeUpdated.setCellphone(systemuser.getCellphone());
            toBeUpdated.setFax(systemuser.getFax());
            toBeUpdated.setEmail(systemuser.getEmail());
            toBeUpdated.setWeb(systemuser.getWeb());
            toBeUpdated.setUnit(systemuser.getUnit());
            toBeUpdated.setAddress(systemuser.getAddress());
            toBeUpdated.setCity(systemuser.getCity());
            toBeUpdated.setProvince(systemuser.getProvince());
            toBeUpdated.setZip(systemuser.getZip());
            toBeUpdated.setCountry(systemuser.getCountry());
            toBeUpdated.setLogopath(systemuser.getLogopath());
            toBeUpdated.setUsersessiontime(systemuser.getUsersessiontime());
            toBeUpdated.setUsersessionpage(systemuser.getUsersessionpage());
            toBeUpdated.setUserlastvisit(systemuser.getUserlastvisit());
            session.update(toBeUpdated);
         }
         tx.commit();
      } catch (HibernateException e) {
         e.printStackTrace();

         // to roll back the transaction after an error occured

         if (tx != null)
            try {
               tx.rollback();
            } catch (HibernateException e1) {
               e1.printStackTrace();
            }

      } finally {
         try {
            if (session != null)
               session.close();
         } catch (HibernateException e1) {
            e1.printStackTrace();
         }
      }
   }



Action

Code:
   public ActionForward saveSystemuser(ActionMapping mapping, ActionForm form,
         HttpServletRequest request, HttpServletResponse response) {
      SystemuserEditForm systemuserEditForm = (SystemuserEditForm) form;

      // get business logic
      VVMManager vvmManager = new VVMManager();
      vvmManager.saveSystemuser(systemuserEditForm.getSystemuser());
      return mapping.findForward("listSystemuser");
   }


JSP Code
Code:
<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>

<html>
<head>
<title>Add a systemuser </title>
</head>
<body>
<%-- create a html form --%>
<html:form action="systemuserEdit">
<html:hidden property="do" value="saveSystemuser"/>
<%-- print out the form data --%>
<table border="1">
<tbody>
<tr>
<td>Userid:</td>
<td><html:text property="userid" /></td> </tr>

<tr>
<td>Active:</td>
<td><html:checkbox property="active" /></td> </tr>

<tr>
<td>Role:</td>
<td><html:text property="role" /></td>
</tr>

<tr>
<td>Username:</td>
<td><html:text property="username" /></td> </tr>

<tr>
<td>Pin:</td>
<td><html:text property="pin" /></td> </tr>

<tr>
<td>Name:</td>
<td><html:text property="name" /></td>
</tr>

<tr>
<td>Personalid:</td>
<td><html:text property="personalid" /></td> </tr>

<tr>
<td>Regdate:</td>
<td><html:text property="regdate" /></td> </tr>

<tr>
<td>Business:</td>
<td><html:checkbox property="business" /></td> </tr>

<tr>
<td>Contact:</td>
<td><html:text property="contact" /></td> </tr>

<tr>
<td>Phone:</td>
<td><html:text property="phone" /></td>
</tr>

<tr>
<td>Cellphone:</td>
<td><html:text property="cellphone" /></td> </tr>

<tr>
<td>Fax:</td>
<td><html:text property="fax" /></td>
</tr>

<tr>
<td>Email:</td>
<td><html:text property="email" /></td>
</tr>

<tr>
<td>Web:</td>
<td><html:text property="web" /></td>
</tr>

<tr>
<td>Unit:</td>
<td><html:text property="unit" /></td>
</tr>

<tr>
<td>Address:</td>
<td><html:text property="address" /></td> </tr>

<tr>
<td>City:</td>
<td><html:text property="city" /></td>
</tr>

<tr>
<td>Province:</td>
<td><html:text property="province" /></td> </tr>

<tr>
<td>Zip:</td>
<td><html:text property="zip" /></td>
</tr>

<tr>
<td>Country:</td>
<td><html:text property="country" /></td> </tr>

<tr>
<td>Logopath:</td>
<td><html:text property="logopath" /></td> </tr>

</tbody>
</table>
<%-- set the parameter for the dispatch action --%> <html:hidden property="do" value="saveSystemuser" />

<br>
<%-- submit and back button --%>
<html:button property="back"
onclick="history.back();">
Back
</html:button>
&nbsp;
<html:submit>Save</html:submit>
</html:form>
</body>
</html>


Code:


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 9:00 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Well maybe you should call getNextException to see the cause as well as posting your mappings.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 01, 2005 2:53 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
lamborghini , if, as you say, you need to wrap the values w/ ticks, use backticks in the mapping declaration.

Code:
<property name="initial" column="`initial`"/>


if you search a forum long enough, you'll find someone w/ the same problem about a week ago .


Top
 Profile  
 
 Post subject: Still working in wrong way
PostPosted: Mon Oct 03, 2005 10:07 am 
Beginner
Beginner

Joined: Mon Sep 19, 2005 3:59 pm
Posts: 31
Hi Denni,

Thanks for your reply, I followed what you told, it seems working in wrong way. It was supposed the values quoted, but the field name quoted.

insert into systemuser ("active", "role", "username", "pin", "name", "personalid", "regdate", "business", "contact", "phone", "cellphone", "fax", "email", "web", "unit", "address", "city", "province", "zip", "country", "logopath", "usersessiontime", "usersessionpage", "userlastvisit", userid) values (1, user, huang, fan, Lindsy, 987, NULL, 1, , , , , , , 0, , , , , , , NULL, NULL, NULL, 5)

Lamborghini.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

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.