I've run into a strange problem with Hibernate save/update/flush. I can edit a record and the changes will save, however, when I create a new record, the new record will NOT save! Below is the code snippits that perform the save and below that is the verbose logging. It show that a save is being performed, but the database (Oracle) is not showing the record as saved. (I've tried using the save option even though it's commented out in this code.)
// Create Museums Action
if (("create".equals(dispatch)) && (errors.empty())) {
MuseumMain museummain=new MuseumMain();
request.getSession().setAttribute(Constants.MUSEUMS, museummain);
util.clearFields(frm);
System.out.println("We are creating!");
} else if (("save".equals(dispatch) || "editsave".equals(dispatch)) && (errors.empty())) {
try {
System.out.println("Top of Save");
String museumId = request.getParameter("id");
SessionFactory sessions = (SessionFactory)this.getServlet().getServletContext().getAttribute(Constants.SESSION_FACTORY);
cn1 = ConnectionPool.getConnection();
Session sess = sessions.openSession(cn1);
MuseumMain museumsmain = (MuseumMain)request.getSession().getAttribute(Constants.MUSEUMS);
museumsmain.setMuseumName((String)frm.get("museumName"));
museumsmain.setOrganization((String)frm.get("organization"));
museumsmain.setRegion((String)frm.get("region"));
museumsmain.setDescription((String)frm.get("description"));
museumsmain.setMailingAddress((String)frm.get("mailingAddress"));
museumsmain.setCity((String)frm.get("city"));
museumsmain.setCounty((String)frm.get("county"));
museumsmain.setState((String)frm.get("state"));
museumsmain.setZip((String)frm.get("zip"));
museumsmain.setPhysicalAddress((String)frm.get("physicalAddress"));
museumsmain.setAreaCode((String)frm.get("areaCode"));
museumsmain.setPhone((String)frm.get("phone"));
museumsmain.setFax((String)frm.get("fax"));
museumsmain.setDiscipline((String)frm.get("discipline"));
//museummain.setMuseumName((String)frm.get("museumName"));
// if ("save".equals(dispatch)) {
// System.out.println("doing save");
// sess.save(museummain);
// } else {
// System.out.println("doing update");
// sess.update(museumsmain);
// }
sess.flush();
sess.close();
Here is my log file:
We are creating!
Top of Save
DEBUG [Thread-4] (SessionImpl.java:413) - opened session
DEBUG [Thread-4] (Cascades.java:208) - unsaved-value: any|none|null|id_value
DEBUG [Thread-4] (SessionImpl.java:1205) - saveOrUpdate() previously saved instance with id: oneone
DEBUG [Thread-4] (SessionImpl.java:1270) - updating [us.ut.state.dced.museums.MuseumMain#oneone]
DEBUG [Thread-4] (SessionImpl.java:2011) - flushing session
DEBUG [Thread-4] (SessionImpl.java:2113) - Flushing entities and processing referenced collections
DEBUG [Thread-4] (SessionImpl.java:2209) - Updating entity: [us.ut.state.dced.museums.MuseumMain#oneone]
DEBUG [Thread-4] (SessionImpl.java:2397) - Processing unreferenced collections
DEBUG [Thread-4] (SessionImpl.java:2408) - Scheduling collection removes/(re)creates/updates
DEBUG [Thread-4] (SessionImpl.java:2023) - Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
DEBUG [Thread-4] (SessionImpl.java:2028) - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG [Thread-4] (SessionImpl.java:2058) - executing flush
DEBUG [Thread-4] (EntityPersister.java:617) - Updating entity: us.ut.state.dced.museums.MuseumMain#oneone
DEBUG [Thread-4] (BatcherImpl.java:166) - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG [Thread-4] (SessionFactoryImpl.java:526) - prepared statement get: update MUSEUMS.MUSEUM_MAIN set ORGANIZATION=?, REGION=?, DESCRIPTION=?, MAILING_ADDRESS=?, CITY=?, COUNTY=?, STATE=?, ZIP=?, PHYSICAL_ADDRESS=?, AREA_CODE=?, PHONE=?, FAX=?, DISCIPLINE=? where MUSEUM_NAME=?
Hibernate: update MUSEUMS.MUSEUM_MAIN set ORGANIZATION=?, REGION=?, DESCRIPTION=?, MAILING_ADDRESS=?, CITY=?, COUNTY=?, STATE=?, ZIP=?, PHYSICAL_ADDRESS=?, AREA_CODE=?, PHONE=?, FAX=?, DISCIPLINE=? where MUSEUM_NAME=?
DEBUG [Thread-4] (SessionFactoryImpl.java:536) - preparing statement
DEBUG [Thread-4] (EntityPersister.java:366) - Dehydrating entity: us.ut.state.dced.museums.MuseumMain#oneone
DEBUG [Thread-4] (NullableType.java:44) - binding 'dkjdkj' to parameter: 1
DEBUG [Thread-4] (NullableType.java:44) - binding 'dkjdkj' to parameter: 2
DEBUG [Thread-4] (NullableType.java:44) - binding 'dkjdkj' to parameter: 3
DEBUG [Thread-4] (NullableType.java:44) - binding '' to parameter: 4
DEBUG [Thread-4] (NullableType.java:44) - binding '' to parameter: 5
DEBUG [Thread-4] (NullableType.java:44) - binding '' to parameter: 6
DEBUG [Thread-4] (NullableType.java:44) - binding '' to parameter: 7
DEBUG [Thread-4] (NullableType.java:44) - binding '' to parameter: 8
DEBUG [Thread-4] (NullableType.java:44) - binding '' to parameter: 9
DEBUG [Thread-4] (NullableType.java:44) - binding '' to parameter: 10
DEBUG [Thread-4] (NullableType.java:44) - binding '' to parameter: 11
DEBUG [Thread-4] (NullableType.java:44) - binding '' to parameter: 12
DEBUG [Thread-4] (NullableType.java:44) - binding '' to parameter: 13
DEBUG [Thread-4] (NullableType.java:44) - binding 'oneone' to parameter: 14
DEBUG [Thread-4] (BatchingBatcher.java:24) - Adding to batch
DEBUG [Thread-4] (BatchingBatcher.java:46) - Executing batch size: 1
DEBUG [Thread-4] (BatcherImpl.java:173) - done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG [Thread-4] (SessionFactoryImpl.java:554) - closing statement
DEBUG [Thread-4] (SessionImpl.java:2428) - post flush
DEBUG [Thread-4] (SessionImpl.java:435) - closing session
DEBUG [Thread-4] (SessionImpl.java:2930) - disconnecting session
DEBUG [Thread-4] (SessionImpl.java:447) - transaction completion
Bottom of Save
DEBUG [Finalizer] (SessionImpl.java:2981) - running Session.finalize()
DEBUG [Thread-4] (SessionImpl.java:413) - opened session
DEBUG [Thread-4] (SessionImpl.java:1328) - find: from us.ut.state.dced.museums.MuseumMain as museummain
DEBUG [Thread-4] (SessionImpl.java:2011) - flushing session
DEBUG [Thread-4] (SessionImpl.java:2113) - Flushing entities and processing referenced collections
DEBUG [Thread-4] (SessionImpl.java:2397) - Processing unreferenced collections
DEBUG [Thread-4] (SessionImpl.java:2408) - Scheduling collection removes/(re)creates/updates
DEBUG [Thread-4] (SessionImpl.java:2023) - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
DEBUG [Thread-4] (SessionImpl.java:2028) - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG [Thread-4] (SessionImpl.java:1573) - Dont need to execute flush
DEBUG [Thread-4] (QueryTranslator.java:200) - HQL: from us.ut.state.dced.museums.MuseumMain as museummain
DEBUG [Thread-4] (QueryTranslator.java:201) - SQL: select museumma0_.MUSEUM_NAME as MUSEUM_NAME, museumma0_.ORGANIZATION as ORGANIZA2_, museumma0_.REGION as REGION, museumma0_.DESCRIPTION as DESCRIPT4_, museumma0_.MAILING_ADDRESS as MAILING_5_, museumma0_.CITY as CITY, museumma0_.COUNTY as COUNTY, museumma0_.STATE as STATE, museumma0_.ZIP as ZIP, museumma0_.PHYSICAL_ADDRESS as PHYSICA10_, museumma0_.AREA_CODE as AREA_CODE, museumma0_.PHONE as PHONE, museumma0_.FAX as FAX, museumma0_.DISCIPLINE as DISCIPLINE from MUSEUMS.MUSEUM_MAIN museumma0_
DEBUG [Thread-4] (BatcherImpl.java:166) - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG [Thread-4] (SessionFactoryImpl.java:526) - prepared statement get: select museumma0_.MUSEUM_NAME as MUSEUM_NAME, museumma0_.ORGANIZATION as ORGANIZA2_, museumma0_.REGION as REGION, museumma0_.DESCRIPTION as DESCRIPT4_, museumma0_.MAILING_ADDRESS as MAILING_5_, museumma0_.CITY as CITY, museumma0_.COUNTY as COUNTY, museumma0_.STATE as STATE, museumma0_.ZIP as ZIP, museumma0_.PHYSICAL_ADDRESS as PHYSICA10_, museumma0_.AREA_CODE as AREA_CODE, museumma0_.PHONE as PHONE, museumma0_.FAX as FAX, museumma0_.DISCIPLINE as DISCIPLINE from MUSEUMS.MUSEUM_MAIN museumma0_
Hibernate: select museumma0_.MUSEUM_NAME as MUSEUM_NAME, museumma0_.ORGANIZATION as ORGANIZA2_, museumma0_.REGION as REGION, museumma0_.DESCRIPTION as DESCRIPT4_, museumma0_.MAILING_ADDRESS as MAILING_5_, museumma0_.CITY as CITY, museumma0_.COUNTY as COUNTY, museumma0_.STATE as STATE, museumma0_.ZIP as ZIP, museumma0_.PHYSICAL_ADDRESS as PHYSICA10_, museumma0_.AREA_CODE as AREA_CODE, museumma0_.PHONE as PHONE, museumma0_.FAX as FAX, museumma0_.DISCIPLINE as DISCIPLINE from MUSEUMS.MUSEUM_MAIN museumma0_
DEBUG [Thread-4] (SessionFactoryImpl.java:536) - preparing statement
DEBUG [Thread-4] (Loader.java:148) - processing result set
Thanks for any help on this!
Scott Ottesen
sottesen@utah.gov