This is sort of "half a problem" I have an object with assigned id. When I create the object and give it an assigned ID, and save the object It throws the stacktrace below
*BUT* everything get's saved in the database as I intended. So it's working, I'd just like to stop the error from happening.
Hibernate version:2.1.5
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.skulls.hibernate.legacy.dbosalehouse.OpenHouse"
table="open_house"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="openId"
column="openId"
type="java.lang.Long"
>
<generator class="assigned">
</generator>
</id>
<property
name="pls"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="pls"
length="11"
not-null="true"
/>
<property
name="startTime"
type="java.sql.Time"
update="true"
insert="true"
access="property"
column="startTime"
length="8"
not-null="true"
/>
<property
name="endTime"
type="java.sql.Time"
update="true"
insert="true"
access="property"
column="endTime"
length="8"
not-null="true"
/>
<property
name="day"
type="java.sql.Date"
update="true"
insert="true"
access="property"
column="day"
length="10"
not-null="true"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-OpenHouse.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
com.skulls.hibernate.legacy.dbosalehouse.OpenHouse hse = new com.skulls.hibernate.legacy.dbosalehouse.OpenHouse();
hse.setOpenId(new Long(h.getId().intValue()));
hse.setPls(h.getProperty());
hse.setDay(new java.sql.Date(h.getStartTime().getTime()));
hse.setStartTime(new java.sql.Time(h.getStartTime().getTime()));
hse.setEndTime(new java.sql.Time(h.getEndTime().getTime()));
UserTransaction tx = null;
try {
InitialContext ctx = new InitialContext();
tx = (UserTransaction) ctx.lookup(TX_NAME);
tx.begin();
Session sess = HibernateContext.getSession(DBO_SALEHOUSE);
sess.save( hse );
} catch (HibernateException e) {
//handle error
}
Full stack trace of any exception that occurs:Code:
08:16:00,234 INFO [STDOUT] net.sf.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.directbyowner.hibernate.legacy.dbosalehouse.OpenHouse
at net.sf.hibernate.id.Assigned.generate(Assigned.java:26)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1387)
Name and version of the database you are using: MySQL 3.2.x
The generated SQL (show_sql=true):Code:
08:16:00,296 INFO [STDOUT] Hibernate: insert into open_house (pls, startTime, endTime, day, openId) values (?, ?, ?, ?, ?)
Debug level Hibernate log excerpt: DEBUG