I am having trouble writing to my database. I apologize that I don't have a stack trace to show you. I think the system is trying to write the values in the wrong order, because when I write, I'm getting this message in the console (please note that id is the last parameter here):
Code:
Hibernate: insert into bulletins (bulletin_date, name, subject, bulletin, approved, id) values (?, ?, ?, ?, ?, ?)
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
Yet when the custom tag I am referencing in the JSP reads from the same table, here is what appears in the console (please note that id is the first parameter here):
Code:
Hibernate: select bulletin0_.id as id, bulletin0_.bulletin_date as bulletin2_3_, bulletin0_.name as name3_, bulletin0_.subject as subject3_, bulletin0_.bulletin as bulletin3_, bulletin0_.approved as approved3_ from bulletins bulletin0_ where bulletin0_.approved=true
Can anyone help me here? Here is the writeBulletin() method in my DAO class:
Code:
public boolean writeBulletin(String name, String subject, String date,
String note) {
Bulletin bulletin = new Bulletin();
request = ServletActionContext.getRequest();
boolean successfulWrite;
SessionFactory sessionFactory = (SessionFactory) request.getSession()
.getServletContext().getAttribute("sessionFactory");
Session session = sessionFactory.openSession();
try {
bulletin.setName(name);
bulletin.setNote(note);
bulletin.setDate(date);
bulletin.setApproved(false);
Transaction tx = session.beginTransaction();
session.save(bulletin);
tx.commit();
successfulWrite = true;
} catch (Exception e) {
System.out.println(e.toString());
successfulWrite = false;
} finally {
session.close();
}
return successfulWrite;
}
For the record, here is the description of my table:
Code:
mysql> describe bulletins;
+---------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| bulletin_date | varchar(10) | NO | | NULL | |
| name | varchar(30) | NO | | NULL | |
| subject | varchar(50) | NO | | NULL | |
| bulletin | varchar(250) | NO | | NULL | |
| approved | tinyint(1) | NO | | NULL | |
+---------------+--------------+------+-----+---------+-------+
6 rows in set (0.01 sec)
Here, also, is Bulletin.hbm.xml:
Code:
<?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" >
<hibernate-mapping>
<class name="model.Bulletin" table="bulletins">
<id name="id" column="id" type="java.lang.Integer">
<generator class="increment" />
</id>
<property name="date" column="bulletin_date" type="java.lang.String" />
<property name="name" column="name" type="java.lang.String" />
<property name="subject" column="subject" type="java.lang.String" />
<property name="note" column="bulletin" type="java.lang.String" />
<property name="approved" column="approved" type="java.lang.Boolean" />
</class>
</hibernate-mapping>